-
-
Notifications
You must be signed in to change notification settings - Fork 480
feat(postgrest): allow select() chaining on write builders #1383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
o-santi
merged 4 commits into
supabase:main
from
Dodothereal:codex/fix-issue-1271-postgrest-write-select
Apr 29, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2083827
feat(postgrest): support select chaining on write builders
Dodothereal 608f50f
Merge branch 'main' into dodo-codex/fix-issue-1271-postgrest-write-se…
o-santi 0e5be5f
fix(postgrest): only ever set return= header once
o-santi 56ed182
fix(postgrest): use time instead of asyncio
o-santi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
PostgREST Prefer header precedence return=minimal return=representation multiple directives💡 Result:
In PostgREST,
Preferfollows RFC 7240. PostgREST supportsPrefer: return=minimal(default for writes) andPrefer: return=representation(return the mutated rows). [1][2]If you send multiple
returndirectives in the same request, e.g.Prefer: return=minimal, return=representation(or across multiplePrefer:header lines)then only the first occurrence is considered and later duplicates should be ignored, per RFC 7240 (“If any preference is specified more than once, only the first instance is to be considered.”). So the leftmost
return=...wins. [2]Also, RFC 7240 notes
return=minimalandreturn=representationare mutually exclusive, so including both is generally a client bug. [2]Sources: [1] PostgREST Prefer header docs, [2] RFC 7240.
🌐 Web query:
PostgREST RFC 7240 Prefer header handling duplicate directives💡 Result:
RFC 7240 defines two relevant rules for
Prefer:Preferheader fields are allowed and are equivalent to a single header whose value is the comma-separated concatenation of all preference tokens. If an HTTP client/library “merges” multiplePreferheaders into one comma-separated header, that’s still compliant. [1]PostgREST follows this RFC 7240 behavior when parsing request headers: if a preference is set more than once (even across multiple
Preferheaders), PostgREST uses the first value and ignores subsequent duplicates. Example from PostgREST’s ownfromHeadersdocs:Prefer: tx=commit, tx=rollbackresults intx=commitbeing used. [2]Separately, PostgREST’s
Prefer: handling=strictis about invalid/unrecognized/unfulfillable preferences (error vs ignore), not about duplicates—duplicates are simply handled as “first wins” per RFC 7240. [3]Sources: RFC 7240 Prefer header specification [1]; PostgREST preference parsing (
fromHeaders) behavior [2]; PostgREST Prefer header docs /handling=strict[3].[1] https://www.rfc-editor.org/rfc/rfc7240
[2] https://hackage.haskell.org/package/postgrest/docs/PostgREST-Request-Preferences.html
[3] https://docs.postgrest.org/en/v12/references/api/preferences.html
🏁 Script executed:
Repository: supabase/supabase-py
Length of output: 444
🏁 Script executed:
Repository: supabase/supabase-py
Length of output: 1614
Replace return= directives in Prefer header instead of appending to avoid return=minimal overriding the intended behavior.
PostgREST follows RFC 7240, which specifies that when a preference appears multiple times, only the first occurrence is honored. If
Preferalready containsreturn=minimalandselect()appends,return=representation, the header becomesreturn=minimal,return=representation—and PostgREST will usereturn=minimal(the first), not the intendedreturn=representation. This breaks embedding behavior.Replace any existing
return=preference instead of appending to ensurereturn=representationis always used:Required fix
Apply the same fix to
SyncQueryRequestBuilder.selectinsrc/postgrest/src/postgrest/_sync/request_builder.pyto keep them synchronized.🤖 Prompt for AI Agents