Skip to content

fix: resolve OMOPHUB_API_KEY and omophub.api_key at client instantiation - #43

Open
chenyangsu wants to merge 2 commits into
OMOPHub:mainfrom
chenyangsu:fix/runtime-api-key-resolution
Open

chenyangsu wants to merge 2 commits into
OMOPHub:mainfrom
chenyangsu:fix/runtime-api-key-resolution

Conversation

@chenyangsu

@chenyangsu chenyangsu commented Dec 1, 2026 •

Copy link
Copy Markdown

Setting os.environ["OMOPHUB_API_KEY"] or omophub.api_key after import omophub still raises AuthenticationError when calling OMOPHub() or AsyncOMOPHub(), because _client.py captures default_api_key once at import time.

Could we resolve the API key at client instantiation in _resolve_api_key() with precedence explicit api_key, then runtime omophub.api_key, then os.environ.get("OMOPHUB_API_KEY")? Happy to read omophub._config directly instead of checking sys.modules["omophub"] if you prefer.

Testing: pytest tests/unit/test_client.py -q -> 26 passed (new tests fail on main), ruff check and mypy src/ clean.


Summary by cubic

Fixes API key resolution so OMOPHUB_API_KEY and omophub.api_key are read at client instantiation instead of at import time. Setting either after import omophub now works when calling OMOPHub() or AsyncOMOPHub(); the precedence is explicit api_key argument, then omophub.api_key, then the OMOPHUB_API_KEY environment variable.

Written for commit 3adf7dd. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread src/omophub/_client.py Resolved
Comment thread src/omophub/_client.py Resolved
Comment thread src/omophub/_client.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant