Per request auth#123
Conversation
Add an optional `auth` parameter to every public client method to override authentication for a single request. Change logic how parameters are passed through, so that it is easier to add more parameters without changing every method definition.
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe client library adds static bearer-token authentication, supports per-request authentication overrides, centralizes HTTP status handling, and forwards shared request parameters across auth, core, and storage clients. Tests and user documentation cover the new authentication behavior. ChangesAuthentication and request flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant CoreClient
participant BaseClient
participant HTTPClient
Caller->>CoreClient: invoke endpoint with auth override
CoreClient->>BaseClient: forward BaseKwargs
BaseClient->>HTTPClient: send request with resolved auth
HTTPClient-->>BaseClient: response
BaseClient-->>CoreClient: model or HubAPIError
CoreClient-->>Caller: endpoint result
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
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 (2)
flame_hub/_core_client.py (1)
680-693: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winMissing return type annotation on
update_project_node.Every sibling
update_*method in this file (update_node,update_analysis,update_analysis_node,update_registry,update_registry_project,update_client, etc.) declares-> ResourceType, but this signature closes with a bare):even though it returnsself._update_resource(...), which resolves toProjectNode.🔧 Proposed fix
def update_project_node( self, project_node_id: ProjectNode | uuid.UUID | str, comment: str | None | UNSET_T = UNSET, approval_status: ProjectNodeApprovalStatus | None | UNSET_T = UNSET, **params: te.Unpack[BaseKwargs], - ): + ) -> ProjectNode: return self._update_resource(🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@flame_hub/_core_client.py` around lines 680 - 693, Add the missing return type annotation to update_project_node, declaring that it returns ProjectNode, consistent with the sibling update_* methods and the value returned by _update_resource.flame_hub/_base_client.py (1)
668-705: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win404-to-
Nonedetection now depends on the response body parsing successfully, regressing from raw status-code checking.Per the diff summary, this previously returned
Nonebased on the raw HTTP status. Now it only returnsNonewhene.error_response is not None and e.error_response.status_code == 404.new_hub_api_error_from_responseleaveserror_responseasNonewheneverr.json()/ErrorResponse(**r.json())raisesValidationError/JSONDecodeError(empty body, non-JSON body, or a body that doesn't validate asErrorResponse— e.g. a generic 404 page from a misconfiguredbase_urlor reverse proxy). In that case this method incorrectly re-raises instead of returningNone, even though the actual HTTP status was 404.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@flame_hub/_base_client.py` around lines 668 - 705, Update the 404 handling in the resource lookup method around the _request call so it checks the raw HTTP response status when HubAPIError.error_response is unavailable, preserving the existing return-None behavior for every 404 response regardless of response-body parsing. Continue re-raising non-404 errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/user_guide.rst`:
- Around line 330-356: Update the PasswordAuth example in the “Overriding
authentication per request” section to use the documented qualified
authentication symbol, such as flame_hub.auth.PasswordAuth, consistent with the
other examples and available imports. Keep the request-specific authentication
behavior unchanged.
In `@flame_hub/_base_client.py`:
- Around line 438-492: Update _request to handle non-expected streamed responses
before calling new_hub_api_error_from_response: read the response body as needed
so error parsing cannot raise ResponseNotRead, and ensure the response is closed
on this error path. Preserve raising HubAPIError for all status mismatches,
including requests made by stream_bucket_tarball and stream_bucket_file.
---
Outside diff comments:
In `@flame_hub/_base_client.py`:
- Around line 668-705: Update the 404 handling in the resource lookup method
around the _request call so it checks the raw HTTP response status when
HubAPIError.error_response is unavailable, preserving the existing return-None
behavior for every 404 response regardless of response-body parsing. Continue
re-raising non-404 errors.
In `@flame_hub/_core_client.py`:
- Around line 680-693: Add the missing return type annotation to
update_project_node, declaring that it returns ProjectNode, consistent with the
sibling update_* methods and the value returned by _update_resource.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 60747e13-4dda-49a1-aca1-b3ff45a75d90
📒 Files selected for processing (11)
README.mddocs/user_guide.rstflame_hub/_auth_client.pyflame_hub/_auth_flows.pyflame_hub/_base_client.pyflame_hub/_core_client.pyflame_hub/_storage_client.pyflame_hub/auth.pyflame_hub/types.pytests/test_base_client.pytests/test_flow.py
…status code Since `new_hub_api_error_from_response()` calls `r.json()`, the response must be read beforehand otherwise a `httpx.ResponseNotRead` is being raised.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation