Skip to content

feat(postgrest): add retry, requestTimeout, abortSignal and setHeader to the typed builders - #1907

Merged
spydon merged 1 commit into
mainfrom
lukasklingsbo/sdk-1837-featpostgrest-retry-requesttimeout-abortsignal-and-setheader
Oct 2, 2026
Merged

spydon merged 1 commit into
mainfrom
lukasklingsbo/sdk-1837-featpostgrest-retry-requesttimeout-abortsignal-and-setheader

Conversation

@spydon

@spydon spydon commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The untyped builders let a caller control each request, but the typed builders returned by client.table(...) could not do any of it. A typed caller had no way to cancel a request, override the timeout or retry policy, or set a header. That includes the Authorization header, which is how a single request overrides the token. The Future.timeout() the typed builder inherits only stops waiting for the result, while the HTTP request keeps running.

This adds retry({bool enabled, int? count}), requestTimeout(Duration), abortSignal(Future<void>) and setHeader(String, String) to PostgrestTypedQueryBuilder, PostgrestTypedFilterBuilder, PostgrestTypedTransformBuilder and PostgrestTypedBuilder. Each one returns its own builder type, so the chain continues. Unlike the untyped API, abortSignal is available at every phase, so .where() still works after it.

final books = await client
    .table(Books.table)
    .select()
    .abortSignal(abort.future)
    .setHeader('Authorization', 'Bearer $token')
    .where(Books.id.eq(1))
    .requestTimeout(const Duration(seconds: 5));

How it works

The typed builders collect an immutable PostgrestTableRequest and a PostgrestTableExecutor runs it. They do not wrap untyped builders, so these settings cannot just be forwarded. Instead:

  • The new PostgrestRequestOptions class holds the headers, the retry override, the timeout and the abort signal. It is stored as PostgrestTableRequest.options, separate from the query fields, because it controls how the request is sent rather than what it asks for. Its dartdoc says an executor that does not use HTTP, such as a cache or a local store, may ignore it, and that a cache keying on the request should leave the abort signal out of the key.
  • PostgrestHttpTableExecutor applies the options to the final untyped builder, for both the normal path and the count() path. Headers the user sets are applied after the builder's own, so they win.
  • Retry follows the untyped retry(): enabled defaults to true, and a count is only overridden when given. If a hand-built options object sets only a count, the client's own retry on/off setting is kept.

Other changes

Tests

  • typed_query_test.dart, through MockSupabaseHttpClient:
    • headers set at every phase reach the wire, including on a table count()
    • setHeader keeps the filter builder, so .where() still follows it
    • retry(enabled: false) sends the request once
    • retry(count:) overrides the client's retry count
    • requestTimeout cancels an attempt that never answers
    • abortSignal cancels a request already in flight, set from the query builder or from the filter builder
  • table_executor_test.dart: the request records the options set at every phase, and has none when nothing is set.

Closes SDK-1837

Summary by CodeRabbit

  • New Features
    • Typed PostgREST queries now support custom request headers, retry settings, per-request timeouts, and cancellation signals. These options can be configured throughout query-building chains and are preserved when builders are copied.

@spydon
spydon requested a review from a team as a code owner October 1, 2026 13:26
@github-actions github-actions Bot added the postgrest This issue or pull request is related to postgrest label Oct 1, 2026
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: supabase/supabase-flutter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: d57477a9-6735-4891-8eb8-1830810844ad

📥 Commits

Reviewing files that changed from the base of the PR and between a5c2098 and b366234.

📒 Files selected for processing (10)
  • AGENTS.md
  • packages/postgrest/lib/src/postgrest_table_executor.dart
  • packages/postgrest/lib/src/postgrest_table_request.dart
  • packages/postgrest/lib/src/postgrest_typed_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_filter_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_query_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_transform_builder.dart
  • packages/postgrest/test/table_executor_test.dart
  • packages/postgrest/test/typed_query_test.dart
  • sdk-compliance.yaml

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


📝 Walkthrough

Walkthrough

Typed PostgREST builders now configure headers, retries, request timeouts, and abort signals. Table requests retain these options, and the HTTP executor applies them to count and non-count requests. Tests cover option propagation and request behavior.

Changes

Typed request options

Layer / File(s) Summary
Request options model
packages/postgrest/lib/src/postgrest_table_request.dart, sdk-compliance.yaml
PostgrestRequestOptions stores headers, retry settings, timeout, and abort signal. PostgrestTableRequest accepts and preserves these options. The capability matrix lists the request-options symbols.
Typed builder configuration
packages/postgrest/lib/src/postgrest_typed_builder.dart, packages/postgrest/lib/src/postgrest_typed_query_builder.dart, packages/postgrest/lib/src/postgrest_typed_filter_builder.dart, packages/postgrest/lib/src/postgrest_typed_transform_builder.dart, AGENTS.md, sdk-compliance.yaml
Typed query, filter, and transform builders add chainable methods for configuring headers, retries, timeouts, and abort signals. The filter builder retains its filter chaining behavior. The builder description and capability matrix include related updates.
Executor application and tests
packages/postgrest/lib/src/postgrest_table_executor.dart, packages/postgrest/test/table_executor_test.dart, packages/postgrest/test/typed_query_test.dart
The executor applies configured options to count and non-count requests. Tests cover option propagation, retry settings, timeouts, abort signals, and unset options.

Priority: ➖ Normal

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant TypedBuilder as PostgrestTypedQueryBuilder
  participant Request as PostgrestTableRequest
  participant Executor as PostgrestHttpTableExecutor
  participant Builder as PostgrestBuilder
  TypedBuilder->>Request: Carry configured request options
  Request->>Executor: Submit request when awaited
  Executor->>Builder: Apply options and render request
Loading

Suggested reviewers: grdsdev

Merge Risk: ⚪ Minimal · up to b3662

This change adds per-request headers, retry, timeout, and cancellation controls to typed PostgREST builders. No merge-blocking issue was found, and tests cover the new behavior.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b3662

The new controls reuse existing request handling, preserve request-scoped headers and do not enable automatic write retries. Remaining uncertainty concerns the outcome of cancelled writes and how custom executors handle identity-bearing options.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new security-relevant reach is from a typed SDK caller supplying a header or token to the HTTP requests that caller constructs, including reads, counts and mutations. The API exposes existing untyped controls but does not itself issue credentials. Actual tenant and data exposure depends on the supplied credential and server authorization, which were not established by this review.

Trust Boundaries and Controls

  • observed — The identity transition is explicit: a request-provided Authorization header wins over the dynamically resolved default token. This precedence predates the typed API addition and remains enforced by the existing token client; the new typed methods do not introduce a separate identity-handling path.

Resilience and Maintainability Implications

  • inferred — Typed mutations now expose the existing transport-cancellation behavior. A timeout or abort exception establishes client-side failure, not database rollback or a known commit outcome. The executor provides no commit reconciliation, and inspected cancellation tests use reads. This is a bounded outcome uncertainty, not a verified unauthorized write or evidence of automatic mutation replay.

Hardening Proposals

  • proposed — Document that cancelled or timed-out mutations can have an unknown outcome, and recommend reconciliation or application-level idempotency before callers repeat security-sensitive writes. This would clarify transport cancellation without promising server rollback.
  • proposed — Clarify that custom caches or local executors handling identity-bearing headers need an explicit identity-partitioning or authorization policy. Permission to ignore transport options should not be interpreted as permission to serve cached data across identities. No production cache defect was established.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding retry, requestTimeout, abortSignal, and setHeader to the typed PostgREST builders.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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 merged commit e7ab358 into main Oct 2, 2026
44 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-1837-featpostgrest-retry-requesttimeout-abortsignal-and-setheader branch October 2, 2026 07:18
spydon added a commit that referenced this pull request Oct 9, 2026
…xecutor (#1939)

## What

#1857 was merged before the plugin seam was ready. This takes the plugin
system and the executor extension point back out of the public API.
#1940 brings them back for review.

The typed builders keep their internal structure: they still collect a
`PostgrestTableRequest` and run it through `PostgrestHttpTableExecutor`.
Several later PRs build on that (#1907, #1913, #1910, #1897 and others).
Only the public surface is removed:

- `SupabaseClientPlugin`, `SupabaseClient(plugins:)`,
`SupabaseClient.plugins`, `Supabase.initialize(plugins:)` and the plugin
resume handling in the Flutter lifecycle listener, and
`testSupabaseClient(plugins:)`.
- `PostgrestClient.table(executor:)`,
`SupabaseQuerySchema(tableExecutor:)` and
`PostgrestTypedBuilder.request`.
- `PostgrestTableExecutor`, `PostgrestHttpTableExecutor`,
`PostgrestTableRequest`, `PostgrestTableResult`,
`PostgrestTableOperation`, `PostgrestResultShape`,
`PostgrestEmbeddedPage`, `PostgrestExplainOptions` and
`PostgrestRequestOptions` are no longer exported.
- `PostgrestTypedQueryBuilder` and `SupabaseTypedQueryBuilder` take a
`client` instead of an `executor`.

The matching `sdk-compliance.yaml` entries and the plugin paragraph in
`MIGRATION.md` are removed, and `AGENTS.md` describes the executor as
internal.

## Tests

`table_executor_test.dart`, `client_plugin_test.dart` and the Flutter
`plugin_test.dart` are removed with the API they cover. They come back
in #1940. The update/delete test in `typed_query_test.dart` used to
assert on `request.filter`. It now checks the filter on the request that
goes out.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Breaking Changes**
* Supabase client initialization no longer accepts plugins, and plugin
lifecycle and request-wrapping support have been removed.
* Typed table queries no longer allow supplying a custom executor.
Supporting typed-query types and request details are no longer exposed
through the main library exports.
* **Documentation**
* Updated query-building and migration guidance to reflect the current
typed table query behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postgrest This issue or pull request is related to postgrest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants