Skip to content

fix: do not raise when both auth header and api_key is passed - #482

Merged
alexanto merged 1 commit into
mainfrom
fix/warn-on-authorization-header
Nov 18, 2026
Merged

alexanto merged 1 commit into
mainfrom
fix/warn-on-authorization-header

Conversation

@alexanto

@alexanto alexanto commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

An Authorization header passed to RequestsTransport or AiohttpTransport no longer always raises ValueError.

Follow-up to the review discussion on Unleash/unleash-documentation#160. Users migrating from v6 might move custom_headers={"Authorization": ...} into the transport and also set api_key. Failing to start in that case is harsher than needed, because the SDK's header replaces theirs. A warning gives them a period to remove it.

Without api_key, the header would be the only credential. Ignoring it silently would send unauthenticated requests and serve default flag values, so failing fast is still the safer choice there, so I kept raising ValueError behaviour.

@sighphyre sighphyre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LG

@github-project-automation github-project-automation Bot moved this from New to Approved PRs in Issues and PRs Nov 18, 2026
@alexanto
alexanto requested a balanced review from Copilot November 18, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the transport authorization migration changes.

No open issues 🎉

What changed in this PR

This PR eases migration from v6 by allowing transport-level Authorization headers alongside api_key. The SDK warns and uses api_key, while still rejecting an authorization header without an API key.

Changes:

  • Move authorization validation from transport construction to client construction.
  • Add tests for warnings, missing-key errors, and header precedence in synchronous and asynchronous transports.
  • Update transport docstrings and README guidance.
File Description
UnleashClient/​transport/​_requests.py Remove constructor rejection and update header documentation.
UnleashClient/​transport/​_aiohttp.py Apply the same changes to the asynchronous transport.
UnleashClient/​transport/​__init__.py Add shared validation that warns or raises based on api_key.
UnleashClient/​clients/​unleash_client.py Validate transport authorization during client construction.
UnleashClient/​clients/​async_unleash_client.py Add equivalent asynchronous-client validation.
tests/​unit_tests/​test_transport.py Verify SDK authorization overrides custom authorization.
tests/​unit_tests/​test_aiohttp_transport.py Verify asynchronous authorization header precedence.
tests/​unit_tests/​clients/​test_unleash_client_transport.py Test warnings and missing-key errors across header casing.
tests/​unit_tests/​clients/​test_async_unleash_client_transport.py Add equivalent asynchronous-client validation tests.
README.md Explain API-key precedence and conditional validation.

Review effort: Balanced

@alexanto
alexanto merged commit 9d5b865 into main Nov 18, 2026
10 checks passed
@alexanto
alexanto deleted the fix/warn-on-authorization-header branch November 18, 2026 12:08
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Issues and PRs Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants