Fix error handling and two subrequests model bugs in the 2.x client - #71
Open
barkerd427 wants to merge 5 commits into
Open
Fix error handling and two subrequests model bugs in the 2.x client#71barkerd427 wants to merge 5 commits into
barkerd427 wants to merge 5 commits into
Conversation
HTTP errors previously flowed into response.json() and were returned as if they were data. Raise httpx.HTTPStatusError instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While building an API consumer on the new 2.x client (thanks for landing #67 — the async support is great!), I hit three small bugs. Each fix comes with unit tests (async + generated sync).
1. Raise on HTTP error responses in resource methods
The resource methods returned
response.json()without checking the status code, so a 4xx/5xx response was returned to the caller as if it were a successful record payload — or crashed with aJSONDecodeErroron an empty/HTML error body.iterate()could also loop on an error payload. This addsresponse.raise_for_status()to all resource HTTP calls so callers get anhttpx.HTTPStatusErrorwith the real status.Note this is a behavior change: code that previously inspected returned error payloads will now see an exception instead. Happy to adjust the approach (e.g. only raise for 5xx, or gate it behind a client option) if you'd prefer to keep the old contract.
2.
SubrequestsBlueprint.roottyped asListinstead ofList[Subrequest]The untyped
Listmeant blueprint members were never validated asSubrequestobjects, so a malformed dict slipped through model validation and failed later at request time.3.
Subrequestmodel validator returnedself.uriPydantic v2
@model_validator(mode="after")must return the model instance. Returningself.urimade every validatedSubrequestcollapse into a plain string, which broke blueprint serialization.New
_synctest files are generated withfarmOS/utils/unasync.py, black/isort/flake8 pass with the repo settings, and CHANGELOG.md is updated under Unreleased.🤖 Generated with Claude Code