Skip to content

fix(postgrest): port small v2 request fixes - #2050

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2824-postgrest-port-small-v2-request-fixes
Nov 13, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2824-postgrest-port-small-v2-request-fixes

Conversation

@spydon

@spydon spydon commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

Four small postgrest request bugs that v2 already fixed, or that turned up while auditing, are still in v3.

What changed

  • Unknown count. With count="planned" or "estimated", PostgREST can answer with * as the total in Content-Range. The response parser called int() on it and raised ValueError after the write had committed. It now returns no count, as v2 does (fix(postgrest): return no count when the total is unknown #1892).
  • max_affected() preferences. Each call appended handling=strict and max-affected= to Prefer, so calling it twice sent both twice. It now drops earlier handling= and max-affected= preferences, including ones packed into a comma-separated value, and keeps the others (fix(postgrest): replace conflicting max-affected preferences #1827, SDK-1704).
  • base_url check. is_http_url existed but was never called, so a client accepted ftp:// or an empty URL and failed only at the first request. PostgrestClient.__init__ now raises ValueError for a URL that is not http or https, or that has no host (fix(postgrest): raise on a non-http base_url #1881, SDK-1667).
  • No body on reads. select() and rpc(get=True) or rpc(head=True) sent {} with Content-Type: application/json on GET and HEAD. delete() sent the same empty body. PostgrestRequest.finalize now sends GET, HEAD and DELETE without a body or content type. Writes with a payload still send their JSON body.

Tests

  • test_unknown_count.py: the header parser and an insert with a */* total, for planned and estimated.
  • test_filter_builder.py: max_affected() called twice, and replacing an existing handling= preference. The existing test that expected a duplicate handling=strict now expects one.
  • test_client_base_url.py: the sync and async clients reject non-http URLs and http:// without a host, and accept http and https.
  • test_bodyless_requests.py: select, head select, rpc GET, rpc HEAD and delete send no body or content type. An insert still sends JSON.

The new tests fail without the source changes.

The related schema() bug, where profile headers are appended instead of replaced, is tracked separately in SDK-2758.

SDK-2824

Return no count when PostgREST reports an unknown total, replace earlier max-affected and handling preferences, reject a non-http base_url, and send GET and HEAD requests without a body.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Invalid base URLs now raise a clear error when initializing a client.
    • Read requests use an empty body and omit the content-type header, while write requests continue to send their data.
    • Responses with an unknown total count now report the count as unavailable instead of treating it as a number.
    • Setting a maximum affected-row limit now replaces conflicting limit and handling preferences while preserving other preferences.

The client now rejects base URLs that are not valid HTTP URLs. GET and HEAD requests use empty request finalization. The max-affected option retains unrelated Prefer directives and replaces existing handling and maximum directives. Count parsing returns no count when the Content-Range total is unknown.

Change: Bug fix

Merge Risk: Minimal · up to 19c47

The change tightens base URL validation, stops sending a body on GET, HEAD, and DELETE requests, replaces earlier handling and max-affected preferences, and treats an unknown count total as no count. No merge-blocking risk was identified.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e2f4b4b8-e75d-4c58-9a1e-fd33f3245475
Commits

Reviewing files that changed from the base of the PR and between 9a5ab35 and 19c47a3.

Files selected for processing: 4

  • src/postgrest/src/postgrest/request_builder.py
  • src/postgrest/src/postgrest/utils.py
  • src/postgrest/tests/test_bodyless_requests.py
  • src/postgrest/tests/test_client_base_url.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@spydon
spydon merged commit f13f7a3 into main Nov 13, 2026
28 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2824-postgrest-port-small-v2-request-fixes branch November 13, 2026 16:26
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.

1 participant