Skip to content

Fix error handling and two subrequests model bugs in the 2.x client - #71

Open
barkerd427 wants to merge 5 commits into
farmOS:mainfrom
barkerd427:2x-fixes
Open

Fix error handling and two subrequests model bugs in the 2.x client#71
barkerd427 wants to merge 5 commits into
farmOS:mainfrom
barkerd427:2x-fixes

Conversation

@barkerd427

Copy link
Copy Markdown
Contributor

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 a JSONDecodeError on an empty/HTML error body. iterate() could also loop on an error payload. This adds response.raise_for_status() to all resource HTTP calls so callers get an httpx.HTTPStatusError with 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.root typed as List instead of List[Subrequest]

The untyped List meant blueprint members were never validated as Subrequest objects, so a malformed dict slipped through model validation and failed later at request time.

3. Subrequest model validator returned self.uri

Pydantic v2 @model_validator(mode="after") must return the model instance. Returning self.uri made every validated Subrequest collapse into a plain string, which broke blueprint serialization.


New _sync test files are generated with farmOS/utils/unasync.py, black/isort/flake8 pass with the repo settings, and CHANGELOG.md is updated under Unreleased.

🤖 Generated with Claude Code

barkerd427 and others added 5 commits July 10, 2026 15:05
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant