Skip to content

feat(postgrest): add client-level retry toggle (postgrest_client_retry) - #1604

Closed
PhuocOng wants to merge 1 commit into
supabase:mainfrom
PhuocOng:feat/postgrest-retry-option
Closed

PhuocOng wants to merge 1 commit into
supabase:mainfrom
PhuocOng:feat/postgrest-retry-option

Conversation

@PhuocOng

@PhuocOng PhuocOng commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Closes #1561.

Adds postgrest_client_retry (default True) to ClientOptions, mirroring postgrest_client_timeout, and forwards it to the PostgREST client as a new retry_enabled constructor option. The flag propagates through schema(), from_()/table() and rpc() into every request builder, so postgrest_client_retry=False disables the automatic retry of transient PostgREST errors for the whole client. The existing per-request .retry() override still takes precedence.

No behavior change by default. _sync mirrors _async. sdk-compliance.yaml gets a note on database.configuration.auto_retry for the client-wide option.

Review guide: the logic lives in four files (postgrest/_async/client.py, postgrest/_async/request_builder.py, supabase/_async/client.py, supabase/lib/client_options.py); the _sync files are line-for-line mirrors, and the rest of the diff is tests.

Tests (TestRetryEnabled, async and sync): the flag propagates through from_/rpc/schema; and, with session.send patched to always answer 503, a client created with retry_enabled=False sends exactly one request, a per-request .retry(True) on that client sends 1 + MAX_RETRIES, and the default client also sends 1 + MAX_RETRIES. test_postgrest_client_retry_option covers the ClientOptions path in supabase. Locally: postgrest 210 passed (integration excluded), supabase 32 passed, mypy clean for both packages, ruff clean.

@PhuocOng

Copy link
Copy Markdown
Contributor Author

hi @o-santi, can you help me review this one please

spydon added a commit that referenced this pull request Nov 2, 2026
## What

Adds a client-level option to turn off automatic retries of transient
PostgREST errors (503/520 on GET/HEAD), matching `db.retry` in
supabase-js.

- `ClientOptions.postgrest_client_retry` (default `True`) is forwarded
to the PostgREST client as `retry_enabled`.
- `AsyncPostgrestClient`/`SyncPostgrestClient` accept `retry_enabled`
and carry it through `schema()`, `from_()`/`table()` and `rpc()` into
every request builder.
- The per-request `.retry()` override still takes precedence.
- `ClientOptions.replace()` keeps `postgrest_client_retry` and accepts a
new value for it.
- The `database.configuration.auto_retry` note in `sdk-compliance.yaml`
now describes the client-wide option.

```python
options = ClientOptions(postgrest_client_retry=False)
client = create_client(url, key, options)
client.table("t").select("*").execute()               # no retries
client.table("t").select("*").retry(True).execute()   # retries for this request
```

## Notes

Supersedes #1604 by @PhuocOng, moved onto current `main` with the
conflicts resolved. Changes since that PR:
- Only the `_async` sources and tests are edited by hand. The `_sync`
trees are generated.
- Tests patch `get_retry_delay` instead of `asyncio.sleep` with
`AsyncMock`, so the generated sync tests work.
- `ClientOptions.replace()` now carries the new field, so it isn't
dropped.

Closes #1561
Linear: SDK-2641

Co-authored-by: Peter Ong <[email protected]>
@spydon

spydon commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the work on this! This has been superseded by #1900, which builds on your changes (with you credited as co-author) and is now merged.

@spydon spydon closed this Nov 3, 2026
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.

parity(client): add db.retry option to disable transient PostgREST retries [from supabase-js]

2 participants