Skip to content

Conversation

@rhamzeh
Copy link
Member

@rhamzeh rhamzeh commented Oct 15, 2025

Description

Generated from: openfga/sdk-generator#638 using

OPEN_API_REF=c0b62b28b14d0d164d37a1f6bf19dc9d39e5769b make test-client-python

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

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

Summary by CodeRabbit

  • New Features

    • Added centralized configuration management for SDK settings, including retry behavior, timeouts, and connection defaults.
  • Chores

    • Refactored internal constants and configuration values to improve maintainability.
    • Updated documentation for contribution guidelines and getting started.
    • Added tests to validate configuration consistency across the SDK.

@codecov-commenter
Copy link

codecov-commenter commented Oct 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.86%. Comparing base (6f06c2f) to head (7eaaf11).

❌ Your project status has failed because the head coverage (70.86%) 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     #236      +/-   ##
==========================================
+ Coverage   70.79%   70.86%   +0.07%     
==========================================
  Files         134      135       +1     
  Lines       10904    10932      +28     
==========================================
+ Hits         7719     7747      +28     
  Misses       3185     3185              

☔ 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR centralizes magic constants scattered across the OpenFGA Python SDK codebase into a new openfga_sdk/constants.py module, refactors code to use these constants instead of hard-coded values, removes auto-generated module docstring headers across numerous files, and adds a test to validate consistency between constants and public exports.

Changes

Cohort / File(s) Summary
Generator Configuration
.openapi-generator-ignore, .openapi-generator/FILES, CONTRIBUTING.md, README.md
Updated generator exclusion patterns; added numerous model modules; removed oauth2, rest, and telemetry modules; removed sync module; updated contributor guidance to redirect issues/PRs to Python SDK repo; updated README navigation.
Constants Module
openfga_sdk/constants.py
New module defining 24 public Final constants for SDK metadata, retry behavior, client limits, headers, connection timeouts, token management, and query duration.
Version and Initialization
openfga_sdk/__init__.py, openfga_sdk/configuration.py
Updated __version__ to import SDK_VERSION from constants; updated RetryParams constructor defaults and validation logic to use centralized constants.
API Client Updates
openfga_sdk/api_client.py, openfga_sdk/sync/api_client.py
Replaced DEFAULT_USER_AGENT with imported USER_AGENT constant; replaced hard-coded retry and backoff values with centralized constants; updated Retry-After header validation threshold.
Client Configuration
openfga_sdk/client/client.py, openfga_sdk/sync/client/client.py
Imported and used CLIENT_METHOD_HEADER, CLIENT_BULK_REQUEST_ID_HEADER, CLIENT_MAX_METHOD_PARALLEL_REQUESTS, CLIENT_MAX_BATCH_SIZE from constants; removed local constant definitions.
OAuth2 Modules
openfga_sdk/oauth2.py, openfga_sdk/sync/oauth2.py
Replaced hard-coded User-Agent strings with USER_AGENT constant imported from constants.
Documentation Header Removals
openfga_sdk/client/__init__.py, openfga_sdk/client/configuration.py, openfga_sdk/client/models/__init__.py, openfga_sdk/client/models/{assertion,batch_check_item,batch_check_request,batch_check_response,batch_check_single_response,check_request,client_batch_check_response,expand_request,list_objects_request,list_relations_request,list_users_request,read_changes_request,tuple,write_request,write_response,write_single_response,write_transaction_opts}.py, openfga_sdk/{credentials,help,rest,validation}.py, openfga_sdk/sync/{__init__,rest}.py, openfga_sdk/telemetry/{__init__,attributes,configuration,counters,histograms,metrics,telemetry}.py
Removed auto-generated module-level docstring headers (cosmetic changes; no functional impact).
Test Documentation Header Removals
test/{__init__,api/__init__,client/__init__,client/client_test,configuration_test,credentials_test,rest_test}.py, test/sync/{__init__,client/__init__,client/client_test,rest_test}.py, test/telemetry/{attributes_test,configuration_test,counters_test,histograms_test,metrics_test,telemetry_test}.py, test/validation_test.py
Removed auto-generated module-level docstring headers from test files.
Test Updates with Constants
test/api/open_fga_api_test.py, test/oauth2_test.py, test/sync/oauth2_test.py, test/sync/open_fga_api_test.py
Imported USER_AGENT from constants; replaced hard-coded User-Agent header strings in test expectations; refactored test_500_error_retry from nested to standalone test method.
New Consistency Test
test/constants_consistency_test.py
New test module validating alignment between __version__ and SDK_VERSION, retry configuration defaults and constants, and User-Agent composition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The PR is mostly consistent patterns applied across many files: centralized constants (straightforward), refactored hard-coded values to use those constants (repetitive), and numerous docstring removals (trivial but numerous). The logic changes are isolated to configuration and client files, but the sheer file count (~80+) warrants moderate review scope despite repetitive patterns.

Possibly related PRs

Suggested reviewers

  • evansims
  • ttrzeng

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "chore: reduce generated code" accurately reflects the main objectives of the changeset. The primary changes include: (1) extracting hardcoded constants throughout the codebase into a new centralized openfga_sdk/constants.py module, (2) removing auto-generated module-level docstrings from numerous files, and (3) updating the .openapi-generator-ignore configuration to control generation scope. All of these changes work together to reduce the amount of generated code and improve maintainability. The title is concise, clear, and appropriately uses the "chore" prefix to indicate this is a maintenance/refactoring task. A reviewer scanning history would immediately understand this PR's intent.

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.

@rhamzeh rhamzeh marked this pull request as ready for review October 23, 2025 17:08
@rhamzeh rhamzeh requested review from a team as code owners October 23, 2025 17:08
Copilot AI review requested due to automatic review settings October 23, 2025 17:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reduces generated code by consolidating constants into a centralized file and removing redundant auto-generated headers from test and SDK files. The changes improve maintainability by eliminating code duplication and establishing a single source of truth for SDK-wide constants.

  • Removed auto-generated file headers from 60+ test and source files
  • Created centralized openfga_sdk/constants.py with all SDK constants marked as Final
  • Refactored hardcoded values to reference centralized constants across client, configuration, and API modules

Reviewed Changes

Copilot reviewed 70 out of 70 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
openfga_sdk/constants.py New centralized constants file with SDK version, URLs, retry configs, client settings, and header names
openfga_sdk/init.py Updated to import SDK_VERSION from constants module
openfga_sdk/configuration.py Refactored to use constants from centralized file for retry parameters and version reporting
openfga_sdk/api_client.py Updated to import and use constants for user agent, timeouts, and retry parameters
openfga_sdk/sync/api_client.py Parallel changes to async api_client for constants usage
openfga_sdk/client/client.py Updated to use constants for client method headers and batch settings
openfga_sdk/sync/client/client.py Parallel changes to async client for constants usage
openfga_sdk/oauth2.py Updated to use USER_AGENT constant
openfga_sdk/sync/oauth2.py Parallel changes to async oauth2 for USER_AGENT constant
test/constants_consistency_test.py New test file ensuring consistency between constants and their usage across modules
test/*/*_test.py Removed auto-generated headers from all test files
README.md Simplified contributing section to reference CONTRIBUTING.md
CONTRIBUTING.md Enhanced with clearer guidance on autogenerated files and PR submission process
.openapi-generator/FILES Updated to reflect new constants file and removed obsolete entries
.openapi-generator-ignore Updated to exclude more autogenerated files from regeneration
Comments suppressed due to low confidence (1)

openfga_sdk/constants.py:1

  • Corrected spelling of 'recieve' to 'receive' in comment on line 5 of constants.py
"""

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
openfga_sdk/api_client.py (1)

251-259: Bug: _retry_params.min_wait_in_ms assigned to wrong variable in two files.

The minimum wait time parameter is being assigned to max_retry instead of min_wait_in_ms, breaking backoff timing and causing type confusion.

Fix required in:

  • openfga_sdk/api_client.py line 257
  • openfga_sdk/sync/api_client.py line 256
 if _retry_params is not None:
     if _retry_params.max_retry is not None:
         max_retry = _retry_params.max_retry
     if _retry_params.min_wait_in_ms is not None:
-        max_retry = _retry_params.min_wait_in_ms
+        min_wait_in_ms = _retry_params.min_wait_in_ms
     if _retry_params.max_wait_in_sec is not None:
         max_wait_in_sec = _retry_params.max_wait_in_sec
🧹 Nitpick comments (2)
test/oauth2_test.py (1)

1720-1759: Make the final 200 OK payload match CheckResponse to avoid false positives.

The success body in this retry test still contains an error schema. Use a minimal valid CheckResponse to assert correctness end‑to‑end.

-        response_body = """
-{
-  "code": "internal_error",
-  "message": "Internal Server Error"
-}
-        """
+        # Use a valid CheckResponse shape for the final 200 OK
+        response_body = """
+{
+  "allowed": true
+}
+        """
openfga_sdk/constants.py (1)

17-20: Consider constructing USER_AGENT from SDK_VERSION to eliminate duplication.

The version "0.9.7" appears in both SDK_VERSION and USER_AGENT, creating a potential desynchronization risk. While the test at test/constants_consistency_test.py:47-50 validates that SDK_VERSION is present in USER_AGENT, constructing the user agent string dynamically would be more robust:

SDK_VERSION: Final[str] = "0.9.7"
USER_AGENT: Final[str] = f"openfga-sdk python/{SDK_VERSION}"

Note: Given that line 10 indicates this file is auto-generated, this change may need to be made in the generation template rather than directly in this file.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f06c2f and fb4227a.

📒 Files selected for processing (70)
  • .openapi-generator-ignore (1 hunks)
  • .openapi-generator/FILES (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • README.md (2 hunks)
  • openfga_sdk/__init__.py (2 hunks)
  • openfga_sdk/api_client.py (3 hunks)
  • openfga_sdk/client/__init__.py (0 hunks)
  • openfga_sdk/client/client.py (4 hunks)
  • openfga_sdk/client/configuration.py (0 hunks)
  • openfga_sdk/client/models/__init__.py (0 hunks)
  • openfga_sdk/client/models/assertion.py (0 hunks)
  • openfga_sdk/client/models/batch_check_item.py (0 hunks)
  • openfga_sdk/client/models/batch_check_request.py (0 hunks)
  • openfga_sdk/client/models/batch_check_response.py (0 hunks)
  • openfga_sdk/client/models/batch_check_single_response.py (0 hunks)
  • openfga_sdk/client/models/check_request.py (0 hunks)
  • openfga_sdk/client/models/client_batch_check_response.py (0 hunks)
  • openfga_sdk/client/models/expand_request.py (0 hunks)
  • openfga_sdk/client/models/list_objects_request.py (0 hunks)
  • openfga_sdk/client/models/list_relations_request.py (0 hunks)
  • openfga_sdk/client/models/list_users_request.py (0 hunks)
  • openfga_sdk/client/models/read_changes_request.py (0 hunks)
  • openfga_sdk/client/models/tuple.py (0 hunks)
  • openfga_sdk/client/models/write_request.py (0 hunks)
  • openfga_sdk/client/models/write_response.py (0 hunks)
  • openfga_sdk/client/models/write_single_response.py (0 hunks)
  • openfga_sdk/client/models/write_transaction_opts.py (0 hunks)
  • openfga_sdk/configuration.py (5 hunks)
  • openfga_sdk/constants.py (1 hunks)
  • openfga_sdk/credentials.py (0 hunks)
  • openfga_sdk/help.py (0 hunks)
  • openfga_sdk/oauth2.py (2 hunks)
  • openfga_sdk/rest.py (0 hunks)
  • openfga_sdk/sync/__init__.py (0 hunks)
  • openfga_sdk/sync/api_client.py (3 hunks)
  • openfga_sdk/sync/client/__init__.py (0 hunks)
  • openfga_sdk/sync/client/client.py (4 hunks)
  • openfga_sdk/sync/oauth2.py (2 hunks)
  • openfga_sdk/sync/rest.py (0 hunks)
  • openfga_sdk/telemetry/__init__.py (0 hunks)
  • openfga_sdk/telemetry/attributes.py (0 hunks)
  • openfga_sdk/telemetry/configuration.py (0 hunks)
  • openfga_sdk/telemetry/counters.py (0 hunks)
  • openfga_sdk/telemetry/histograms.py (0 hunks)
  • openfga_sdk/telemetry/metrics.py (0 hunks)
  • openfga_sdk/telemetry/telemetry.py (0 hunks)
  • openfga_sdk/validation.py (0 hunks)
  • test/__init__.py (0 hunks)
  • test/api/__init__.py (0 hunks)
  • test/api/open_fga_api_test.py (5 hunks)
  • test/client/__init__.py (0 hunks)
  • test/client/client_test.py (0 hunks)
  • test/configuration_test.py (0 hunks)
  • test/constants_consistency_test.py (1 hunks)
  • test/credentials_test.py (0 hunks)
  • test/oauth2_test.py (8 hunks)
  • test/rest_test.py (0 hunks)
  • test/sync/__init__.py (0 hunks)
  • test/sync/client/__init__.py (0 hunks)
  • test/sync/client/client_test.py (0 hunks)
  • test/sync/oauth2_test.py (4 hunks)
  • test/sync/open_fga_api_test.py (6 hunks)
  • test/sync/rest_test.py (0 hunks)
  • test/telemetry/attributes_test.py (0 hunks)
  • test/telemetry/configuration_test.py (0 hunks)
  • test/telemetry/counters_test.py (0 hunks)
  • test/telemetry/histograms_test.py (0 hunks)
  • test/telemetry/metrics_test.py (0 hunks)
  • test/telemetry/telemetry_test.py (0 hunks)
  • test/validation_test.py (0 hunks)
💤 Files with no reviewable changes (52)
  • openfga_sdk/sync/client/init.py
  • test/telemetry/attributes_test.py
  • openfga_sdk/client/models/read_changes_request.py
  • openfga_sdk/client/models/init.py
  • test/telemetry/histograms_test.py
  • test/init.py
  • test/sync/rest_test.py
  • test/sync/client/init.py
  • test/credentials_test.py
  • openfga_sdk/telemetry/counters.py
  • openfga_sdk/client/models/list_relations_request.py
  • openfga_sdk/client/models/tuple.py
  • test/sync/client/client_test.py
  • openfga_sdk/telemetry/histograms.py
  • openfga_sdk/client/models/assertion.py
  • openfga_sdk/client/models/write_response.py
  • openfga_sdk/client/models/list_objects_request.py
  • openfga_sdk/telemetry/telemetry.py
  • openfga_sdk/client/models/write_transaction_opts.py
  • openfga_sdk/client/models/list_users_request.py
  • openfga_sdk/client/models/batch_check_single_response.py
  • openfga_sdk/sync/rest.py
  • openfga_sdk/client/models/check_request.py
  • openfga_sdk/telemetry/init.py
  • test/configuration_test.py
  • openfga_sdk/client/models/batch_check_response.py
  • openfga_sdk/credentials.py
  • openfga_sdk/client/models/batch_check_request.py
  • test/telemetry/telemetry_test.py
  • openfga_sdk/client/configuration.py
  • openfga_sdk/client/init.py
  • test/telemetry/configuration_test.py
  • openfga_sdk/client/models/client_batch_check_response.py
  • openfga_sdk/client/models/expand_request.py
  • test/validation_test.py
  • test/client/client_test.py
  • openfga_sdk/rest.py
  • openfga_sdk/telemetry/metrics.py
  • openfga_sdk/client/models/batch_check_item.py
  • openfga_sdk/sync/init.py
  • openfga_sdk/help.py
  • test/sync/init.py
  • openfga_sdk/telemetry/attributes.py
  • openfga_sdk/client/models/write_request.py
  • test/rest_test.py
  • openfga_sdk/client/models/write_single_response.py
  • openfga_sdk/telemetry/configuration.py
  • test/client/init.py
  • test/api/init.py
  • test/telemetry/metrics_test.py
  • test/telemetry/counters_test.py
  • openfga_sdk/validation.py
🧰 Additional context used
🧬 Code graph analysis (5)
openfga_sdk/sync/client/client.py (1)
openfga_sdk/client/models/write_transaction_opts.py (2)
  • max_parallel_requests (51-55)
  • max_parallel_requests (58-65)
test/constants_consistency_test.py (1)
openfga_sdk/configuration.py (10)
  • api_url (701-703)
  • api_url (706-708)
  • retry_params (733-737)
  • retry_params (740-744)
  • max_retry (53-62)
  • max_retry (65-79)
  • min_wait_in_ms (82-86)
  • min_wait_in_ms (89-98)
  • max_wait_in_sec (101-105)
  • max_wait_in_sec (108-117)
test/sync/open_fga_api_test.py (2)
openfga_sdk/api_client.py (1)
  • ApiClient (44-920)
openfga_sdk/sync/api_client.py (1)
  • ApiClient (43-918)
openfga_sdk/configuration.py (1)
openfga_sdk/exceptions.py (1)
  • FgaValidationException (36-61)
openfga_sdk/client/client.py (1)
openfga_sdk/client/models/write_transaction_opts.py (2)
  • max_parallel_requests (51-55)
  • max_parallel_requests (58-65)
🪛 LanguageTool
CONTRIBUTING.md

[style] ~39-~39: Consider using a less common alternative to make your writing sound more unique and professional.
Context: ...acker.** ### Submitting Pull Requests Feel free to submit a Pull Request against this repo...

(FEEL_FREE_TO_STYLE_ME)

🔇 Additional comments (19)
test/sync/oauth2_test.py (1)

8-8: Good switch to centralized USER_AGENT.

Using openfga_sdk.constants.USER_AGENT keeps tests aligned with client defaults and reduces drift.

Also applies to: 76-77, 134-135, 193-194

openfga_sdk/oauth2.py (1)

12-12: Consistent User-Agent source.

Importing USER_AGENT and using it in token requests is correct and removes hardcoded strings.

Also applies to: 82-83

test/oauth2_test.py (1)

9-9: LGTM on USER_AGENT centralization.

All header expectations now use the shared constant; consistent with client defaults.

Also applies to: 76-77, 302-303, 358-359, 413-414, 526-527, 585-586

test/sync/open_fga_api_test.py (3)

12-12: Importing USER_AGENT here is correct.

Keeps sync tests aligned with the new constants module.


1720-1759: Retry behavior test reads well.

Covers multiple 5xx codes and a final success; call_count assertion matches side effects.

If you want parity with the async test, consider asserting a field on the parsed response as well.


1835-1836: Headers now use USER_AGENT constant — nice.

Reduces duplication and future‑proofs tests against UA changes.

Also applies to: 1890-1891, 1947-1948, 2003-2004

openfga_sdk/__init__.py (1)

6-6: Version derives from SDK_VERSION.

Good centralization; avoids manual bumps.

Also applies to: 134-135

openfga_sdk/api_client.py (2)

19-24: Centralized constants import is correct.

Alias for DEFAULT_USER_AGENT preserves the public symbol while sourcing from constants.


418-421: Good guardrail for Retry‑After header.

Using RETRY_HEADER_MAX_ALLOWABLE_DURATION_IN_SEC avoids unbounded sleeps.

openfga_sdk/configuration.py (5)

9-15: Correct consolidation of defaults and version.

Imports bring retry/backoff and version constants into one place.


42-47: RetryParams defaults now come from constants.

Appropriate centralization; matches the rest of the refactor.


57-60: Bound check on max_retry in getter.

Prevents invalid configs from silently passing.

Consider mirroring a similar upper bound on max_wait_in_sec if you want to cap sleep even when not using Retry‑After.


74-77: Setter validation message is clear and constant‑driven.

Error text references RETRY_MAX_ALLOWED_NUMBER; good.


546-547: Debug report reflects SDK_VERSION.

Avoids stale version strings.

test/constants_consistency_test.py (1)

26-50: LGTM! Well-structured consistency tests.

The test functions effectively validate alignment between constants and their usage across the SDK. The coverage includes version consistency, retry parameter defaults, and user agent constants for both sync and async clients.

openfga_sdk/sync/api_client.py (3)

17-21: LGTM! Constants properly centralized.

The imports from openfga_sdk.constants successfully replace local definitions, improving maintainability. The alias USER_AGENT as DEFAULT_USER_AGENT preserves the existing API surface.


244-251: LGTM! Hardcoded value replaced with constant.

Replacing the hardcoded 120 with MAX_BACKOFF_TIME_IN_SEC improves maintainability and ensures consistency across the codebase.


416-422: LGTM! Retry header validation uses centralized constant.

Replacing the hardcoded 1800 with RETRY_HEADER_MAX_ALLOWABLE_DURATION_IN_SEC ensures consistent behavior across retry logic and improves code clarity.

openfga_sdk/constants.py (1)

1-93: LGTM! Well-organized constants module.

The constants are logically grouped, comprehensively documented, and properly typed with Final. This centralization will significantly improve maintainability across the SDK.

Co-authored-by: Copilot <[email protected]>
@rhamzeh rhamzeh added this pull request to the merge queue Oct 24, 2025
Merged via the queue into main with commit 759afd0 Oct 24, 2025
28 checks passed
@rhamzeh rhamzeh deleted the chore/reduce-generation branch October 24, 2025 18:10
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.

4 participants