Skip to content

Conversation

dyeam0
Copy link
Member

@dyeam0 dyeam0 commented Sep 7, 2025

⚠️ DO NOT MERGE - For Review Only

This PR is a proposed fix for a critical header precedence bug where default headers incorrectly override per-request custom headers, plus comprehensive test coverage to validate the fix.

** Do not merge - Proposed fix for review only. **

Description

What problems are being solved?

  1. Header precedence bug: Default headers incorrectly override per-request custom headers, preventing users from overriding defaults for tracing, correlation IDs, etc.
  2. Missing test coverage: There are no tests for per-request custom HTTP headers functionality across API methods and edge cases

How are they being solved?

  1. Bug fix: Fixed header merging logic in api_client.py (both sync and async versions)
  2. Comprehensive testing: Added extensive test coverage for per-request custom HTTP headers to validate the fix and prevent regressions

What changes are made to solve them?

Bug fixes:

  • Fixed header merging logic in openfga_sdk/sync/api_client.py and openfga_sdk/api_client.py
  • Per-request headers now properly override default headers when conflicts exist
  • Maintains authentication header precedence

Testing improvements:

  • Add core functionality tests for all API methods (check, write, read, etc.)
  • Add edge case tests for invalid inputs and boundary conditions
  • Add synchronous client compatibility tests
  • Add summary test demonstrating real-world usage patterns
  • Covers both async and sync clients with 1,270+ lines of test coverage

Issues Addressed

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/per-request-headers-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dyeam0 dyeam0 force-pushed the feature/per-request-headers-tests branch 2 times, most recently from e21322a to 02b1b41 Compare September 7, 2025 22:14
…lity + fix SDK bugs

Tests:
- Add core functionality tests for all API methods (check, write, read, etc.)
- Add edge case tests for invalid inputs and boundary conditions
- Add synchronous client compatibility tests
- Add summary test demonstrating real-world usage patterns
- Covers both async and sync clients with 1,270+ lines of test coverage

SDK Bug Fixes:
- Fix header merging logic in both ApiClient classes to allow custom headers to override default headers
- Add validation in options_to_kwargs to handle invalid header types gracefully
- Previously default headers would overwrite custom headers due to incorrect merge order
- Now custom headers properly take precedence over defaults (except system headers like Accept/Content-Type)

All async tests pass. Sync client tests need additional investigation.

Resolves #217
@dyeam0 dyeam0 force-pushed the feature/per-request-headers-tests branch from 02b1b41 to 4fd086c Compare September 7, 2025 22:27
- Fix header merging logic in sync API client: custom headers now properly override defaults
- Fix string decoding bug in sync API client: handle both bytes and string data gracefully
- Fix invalid ULID format in sync client tests
- Resolve all ruff linting issues in test files
- All 35 comprehensive tests now passing (async: 29/29, sync: 6/6, edge cases: 15/15, summary: 1/1)
- Zero regressions in existing functionality

This commit resolves all failing CI jobs and delivers fully functional per-request headers.
@codecov-commenter
Copy link

codecov-commenter commented Sep 7, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.00%. Comparing base (89a39d1) to head (d6934d8).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
openfga_sdk/sync/client/client.py 75.00% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (71.00%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #218      +/-   ##
==========================================
+ Coverage   70.70%   71.00%   +0.30%     
==========================================
  Files         134      134              
  Lines       10881    10953      +72     
==========================================
+ Hits         7693     7777      +84     
+ Misses       3188     3176      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add test for streamed_list_objects with custom headers
- Improve test coverage for header merging edge cases
- Validate that custom headers properly override defaults across all sync API methods
@dyeam0 dyeam0 changed the title Add tests for per-request custom HTTP headers functionality (DO NOT MERGE) Fix header precedence bug & add comprehensive tests for per-request headers Sep 14, 2025
- Add missing ClientListObjectsRequest import at top of file
- Remove duplicate import from middle of function
- Fix trailing whitespace on blank line
@evansims evansims self-assigned this Sep 17, 2025
@evansims
Copy link
Member

evansims commented Oct 3, 2025

Superceded by #230

@evansims evansims closed this Oct 3, 2025
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.

Add tests for per-request custom HTTP headers functionality Default headers incorrectly override per-request custom headers
3 participants