Skip to content

fix(postgrest)!: stop transforms from silently changing or dropping part of a request - #2026

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2333-fixpostgrest-transforms-that-silently-change-or-drop-part-of
Oct 23, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2333-fixpostgrest-transforms-that-silently-change-or-drop-part-of

Conversation

@spydon

@spydon spydon commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Linear: https://linear.app/supabase/issue/SDK-2333/fixpostgrest-transforms-that-silently-change-or-drop-part-of-a-request

What changed

Six builder methods compiled but sent something other than what was asked for. Each one now either sends the right request or fails at the call site.

  1. head() after a write. It used to turn an insert, upsert, update or delete into a HEAD, so the write never happened and the call still succeeded. Both surfaces now throw a StateError when head() is called after a write. A select, a count and a function call still send a HEAD.
  2. maybeSingle() on a write. An insert, upsert, update or delete now sends Accept: application/vnd.pgrst.object+json, as single() does. A delete or update that matches several rows is rolled back by PostgREST before the error reaches the caller. Before, it was committed and then the call threw. The 406 that PostgREST returns when no row matched is turned back into null (count 0). Reads and function calls still enforce the limit client-side, so a read that finds nothing does not cause a 406. single() after maybeSingle() clears the flag, so a zero-row result still throws PGRST116.
  3. Typed count(). It returns a new PostgrestTypedCountBuilder with where() and the request options (retry, requestTimeout, abortSignal, setHeader) but no transforms. limit() and range() used to be dropped silently, and csv(), select() and explain() crashed with a null check error. PostgrestHttpTableExecutor also rejects a hand-built count request that carries a limit, offset, ordering, embed scope or result shape.
  4. Untyped rpc(...).head(). The arguments are moved into the query string, which the typed executor already did. A HEAD has no body to fall back on, so on both surfaces head() throws an ArgumentError for arguments PostgREST would not pass to the function: a name like limit or order, a value like eq.1, a null, or arguments that are not a Map. The check is the one the typed executor already used to decide whether a read-only call can be a GET, now shared as postgrestArgumentsFitQuery.
  5. Untyped rpc('fn', get: true) without params. It sends a bare GET instead of throwing ArgumentError: argument must be a Map: null. Both GET and HEAD calls now share one helper that builds the query string from the arguments.
  6. range(from, to) with to < from. It throws an ArgumentError on the untyped builder (including referencedTable), the typed builder and PostgrestEmbeddedScope.range. The typed executor now sets the offset and limit through an internal window() step instead of re-deriving a range(), so .range(5, 9).limit(0) still sends offset=5&limit=0 and does not trip the new check.

maybeSingle() on writes

Item 2 deliberately partly reverses #1779, which stopped sending the object Accept header for every request method so that a write matching no row would not log a 406. Without the header, PostgREST commits every row a write matched before the client can count them, so a maybeSingle() update or delete with a too broad filter changes several rows and only then throws. Only the header lets PostgREST roll that write back. The known cost is that a write matching no row logs a 406 on the server again, while the caller still gets null. Reads and function calls, where nothing is changed and "fetch it if it exists" is the common case, keep the client-side check and stay free of 406s.

Breaking changes

MIGRATION.md gets one section, "Transforms that sent a different request now throw or narrow", which is also linked from "Changes the compiler will not catch". PostgrestTypedCountBuilder and its members are registered in sdk-compliance.yaml. checkPostgrestRange, checkPostgrestHeadArguments, postgrestArgumentsFitQuery and PostgrestTransformBuilder.window are @internal, and the top-level ones are hidden from the library export.

Tests

  • test/transform_request_test.dart adds a regression test for each item, run against MockSupabaseHttpClient. Each one checks the method, query parameters and headers that go out, on both surfaces where both exist. It also covers the review follow-ups: head() arguments, maybeSingle() on an rpc call, maybeSingle().single() and the executor's count guard.
  • test/maybe_single_test.dart now checks the read-only behavior. The write cases moved into the new file.
  • test/basic_test.dart adds two tests against the local stack. A maybeSingle() update that matches three rows throws PGRST116, and afterwards all three rows are still unchanged. An update that matches no row resolves to null.

Summary by CodeRabbit

  • New Features

    • Added a typed count builder that supports filtering and request configuration, without row transforms.
    • GET function calls can now pass arguments as query parameters when they meet the supported format.
  • Behavior Changes

    • Invalid or reversed ranges now throw an error.
    • head() is supported for reads and eligible function calls; using it after a write now throws an error.
    • maybeSingle() returns null for zero-row results. Writes matching multiple rows are rolled back before an error is reported.
    • Count requests with unsupported transforms are rejected.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between f94247d and 3e9dc14.

📒 Files selected for processing: 16
  • MIGRATION.md
  • packages/postgrest/lib/postgrest.dart
  • packages/postgrest/lib/src/postgrest_builder.dart
  • packages/postgrest/lib/src/postgrest_embedded_scope.dart
  • packages/postgrest/lib/src/postgrest_filter.dart
  • packages/postgrest/lib/src/postgrest_rpc_builder.dart
  • packages/postgrest/lib/src/postgrest_table_executor.dart
  • packages/postgrest/lib/src/postgrest_transform_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_count_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_query_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_transform_builder.dart
  • packages/postgrest/test/basic_test.dart
  • packages/postgrest/test/maybe_single_test.dart
  • packages/postgrest/test/transform_request_test.dart
  • sdk-compliance.yaml

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 587a253 and f94247d.

📒 Files selected for processing: 16
  • MIGRATION.md
  • packages/postgrest/lib/postgrest.dart
  • packages/postgrest/lib/src/postgrest_builder.dart
  • packages/postgrest/lib/src/postgrest_embedded_scope.dart
  • packages/postgrest/lib/src/postgrest_filter.dart
  • packages/postgrest/lib/src/postgrest_rpc_builder.dart
  • packages/postgrest/lib/src/postgrest_table_executor.dart
  • packages/postgrest/lib/src/postgrest_transform_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_count_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_query_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_transform_builder.dart
  • packages/postgrest/test/basic_test.dart
  • packages/postgrest/test/maybe_single_test.dart
  • packages/postgrest/test/transform_request_test.dart
  • sdk-compliance.yaml

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

📝 Walkthrough

The PostgREST Dart builders now provide a typed count builder, validate range and head transforms, route eligible RPC arguments through query parameters, and handle zero-row maybeSingle() responses separately from other errors.

Changes: PostgREST request builders

Layer / File(s) Summary
Typed count builder and request constraints
packages/postgrest/lib/src/postgrest_typed_count_builder.dart, packages/postgrest/lib/src/postgrest_typed_query_builder.dart, packages/postgrest/lib/src/postgrest_table_executor.dart, packages/postgrest/lib/src/postgrest_typed_builder.dart, sdk-compliance.yaml, packages/postgrest/test/transform_request_test.dart
count() returns a typed count builder that supports filters and request configuration. The executor rejects count requests with limits, offsets, ordering, embedded scopes, or unsupported result shapes.
Range, head, and RPC request handling
packages/postgrest/lib/src/postgrest_transform_builder.dart, packages/postgrest/lib/src/postgrest_typed_transform_builder.dart, packages/postgrest/lib/src/postgrest_embedded_scope.dart, packages/postgrest/lib/src/postgrest_table_executor.dart, packages/postgrest/lib/src/postgrest_rpc_builder.dart, packages/postgrest/lib/src/postgrest_filter.dart, packages/postgrest/lib/src/postgrest_builder.dart, packages/postgrest/lib/postgrest.dart, packages/postgrest/test/transform_request_test.dart, MIGRATION.md
Range methods reject reversed bounds, and offset-plus-limit handling uses window(). head() rejects writes and validates function-call arguments. Eligible RPC arguments are added to the URL for GET and HEAD requests. The migration guide documents these changes.
maybeSingle response behavior
packages/postgrest/lib/src/postgrest_builder.dart, packages/postgrest/lib/src/postgrest_transform_builder.dart, packages/postgrest/test/basic_test.dart, packages/postgrest/test/maybe_single_test.dart, packages/postgrest/test/transform_request_test.dart
For a PGRST116 error whose details match 0 rows, maybeSingle() returns null data and count zero. Writes request the object response media type; reads and function calls do not. Tests cover zero-row and multirow write results.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: vinzent03

Merge Risk: ⚪ Minimal · up to f9424

The reported RPC argument issue does not change valid request behavior. No actionable merge-blocking risk remains from the supplied evidence.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: transforms on PostgREST builders now throw or reject requests instead of silently changing or dropping parts of them. The changeset covers head(), maybeSingle(), count…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: transforms on PostgREST builders now throw or reject requests instead of silently changing or dropping parts of them. The changeset covers head(), maybeSingle(), count(), rpc head/GET handling, and range() validation, all of which match the title's scope. The title uses the conventional commit form with a breaking-change marker, which fits the breaking behavior documented in MIGRATION.md.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (16 skipped: 16 unsupported.)

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@spydon
spydon force-pushed the lukasklingsbo/sdk-2333-fixpostgrest-transforms-that-silently-change-or-drop-part-of branch 2 times, most recently from f94247d to 5b7aee5 Compare October 23, 2026 13:12
…art of a request

head() throws after a write instead of turning it into a HEAD, maybeSingle()
asks for a single object on writes so PostgREST rolls back a multi-row write,
typed count() returns a PostgrestTypedCountBuilder with filters only, an
untyped rpc(...).head() sends its arguments as query parameters,
rpc(get: true) accepts no params, and range() rejects an end before the
start.
…eep maybeSingle() client-side for function calls

head() on a function call throws when an argument would be read as an
option or a filter, maybeSingle() leaves the Accept header of an rpc call
alone, single() clears a preceding maybeSingle(), and the table executor
rejects a count request that carries transforms.
@spydon
spydon force-pushed the lukasklingsbo/sdk-2333-fixpostgrest-transforms-that-silently-change-or-drop-part-of branch from d357f98 to 3e9dc14 Compare October 23, 2026 13:53
@spydon
spydon merged commit f9924ac into main Oct 23, 2026
47 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2333-fixpostgrest-transforms-that-silently-change-or-drop-part-of branch October 23, 2026 14:02
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