-
Notifications
You must be signed in to change notification settings - Fork 61
fix(python-sdk): custom header precedence #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughHeader composition logic updated to merge default and per-request headers with per-request precedence in both async and sync clients. The set_heading_if_not_set behavior changed to only set a header when it is missing. Extensive async and sync tests were added to validate header merging, overrides, and the new helper’s behavior. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App
participant Client as OpenFgaClient
participant API as ApiClient
participant HTTP as RESTClientObject
App->>Client: call operation(options with _headers?)
Client->>Client: set_heading_if_not_set(options, name, value)\n(only if missing)
Client->>API: invoke API method with options.headers
API->>API: header_params = {**default_headers, **(options.headers or {})}
API->>HTTP: request(method, url, headers=header_params)
HTTP-->>API: response
API-->>Client: parsed response
Client-->>App: result
note over API,HTTP: Per-request headers take precedence over defaults
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
config/clients/python/template/src/api_client.py.mustache(1 hunks)config/clients/python/template/src/client/client.py.mustache(1 hunks)config/clients/python/template/src/sync/api_client.py.mustache(1 hunks)config/clients/python/template/src/sync/client/client.py.mustache(1 hunks)config/clients/python/template/test/api_test.py.mustache(1 hunks)config/clients/python/template/test/client/client_test.py.mustache(2 hunks)config/clients/python/template/test/sync/api_test.py.mustache(1 hunks)config/clients/python/template/test/sync/client/client_test.py.mustache(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
config/**/*.mustache
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Validate mustache syntax and variable references across all template files, including CHANGELOG.md.mustache
Files:
config/clients/python/template/src/client/client.py.mustacheconfig/clients/python/template/src/sync/client/client.py.mustacheconfig/clients/python/template/test/api_test.py.mustacheconfig/clients/python/template/test/sync/client/client_test.py.mustacheconfig/clients/python/template/test/sync/api_test.py.mustacheconfig/clients/python/template/test/client/client_test.py.mustacheconfig/clients/python/template/src/api_client.py.mustacheconfig/clients/python/template/src/sync/api_client.py.mustache
config/**/*.{json,mustache}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Never hardcode API keys or credentials in configuration or template files
Files:
config/clients/python/template/src/client/client.py.mustacheconfig/clients/python/template/src/sync/client/client.py.mustacheconfig/clients/python/template/test/api_test.py.mustacheconfig/clients/python/template/test/sync/client/client_test.py.mustacheconfig/clients/python/template/test/sync/api_test.py.mustacheconfig/clients/python/template/test/client/client_test.py.mustacheconfig/clients/python/template/src/api_client.py.mustacheconfig/clients/python/template/src/sync/api_client.py.mustache
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-and-test-java-sdk
🔇 Additional comments (2)
config/clients/python/template/test/sync/client/client_test.py.mustache (2)
3269-3397: Excellent test coverage for the header helper function.The 15 unit tests for
set_heading_if_not_setprovide comprehensive validation of the bug fix and edge cases:
- Core bug fix validation (line 3300): ensures existing headers are NOT overridden
- Proper handling of missing/empty options and headers
- Edge cases: non-dict headers, unicode, special characters, case sensitivity
- Mutation behavior: preserves existing values and other headers
The test suite clearly demonstrates the intended behavior and will prevent regressions.
3399-3594: Comprehensive integration test coverage for custom headers.The 8 integration tests validate that custom headers work correctly across all major API methods:
- Single API calls (check, write, expand, list_objects, list_users)
- Batch operations (client_batch_check)
- Multiple sequential calls with different headers
This thorough coverage ensures that the header precedence fix works end-to-end from the client layer through to the REST client, preventing regressions across the entire API surface.
This PR addresses a bug in which, when calling a Client API method with custom headers, those headers may not be sent as expected. An issue related to the way header merging was occurring could result in custom headers being dropped.
Before:
After:
References
Builds → openfga/python-sdk#230
Review Checklist
mainSummary by CodeRabbit