feat(postgrest): support single()/maybe_single() after insert/upsert select - #1557
Open
tushardev-365 wants to merge 1 commit into
Open
feat(postgrest): support single()/maybe_single() after insert/upsert select#1557tushardev-365 wants to merge 1 commit into
tushardev-365 wants to merge 1 commit into
Conversation
…select insert() and upsert() return an *QueryRequestBuilder, whose select() returns self, so single()/maybe_single() were unreachable and the JS client chain insert(...).select().single() had no Python equivalent (supabaseGH-1553). Move single()/maybe_single() up to *QueryRequestBuilder so they are available on every builder that select() can return, matching the JS client. Sync code and tests are the unasync-generated mirror. Closes supabase#1553
Contributor
|
I'm afraid that this might allow |
Contributor
Author
|
Yeah, this matches how JS is structured. There JS doesn't gate the "doesn't make sense" cases either: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Closes #1553.
The JS client supports
client.from("t").insert(...).select().single(), but the Python client didn't:insert()andupsert()return a*QueryRequestBuilder, whoseselect()returnsself, andsingle()/maybe_single()only lived on*SelectRequestBuilder. So after an insert/upsert there was no way to get a single-row response.Change
Move
single()andmaybe_single()up from*SelectRequestBuilderto the base*QueryRequestBuilder. They're now reachable from every builderselect()can return, so all of these work and mirror the JS client:*SelectRequestBuilderstill exposes them via inheritance, so existingselect().single()usage is unchanged. The methods only set headers and return the existing single/maybe-single builders, so there's no behavioural change to whatsingle()itself does.Async is the source of truth; the sync builder and both test files are the unasync-generated mirror.
Testing
Added
test_select_single/test_select_maybe_singleto the query-request-builder tests (async + sync), assertingselect().single()returns the single-request builder with theapplication/vnd.pgrst.object+jsonAccept header andselect().maybe_single()returns the maybe-single builder. Full postgrest unit suite passes: