Skip to content

fix(postgrest): throw on multi-row Single() result instead of returning null - #346

Open
fresh55 wants to merge 1 commit into
supabase-community:masterfrom
fresh55:fix/postgrest-single-multirow-406
Open

fix(postgrest): throw on multi-row Single() result instead of returning null#346
fresh55 wants to merge 1 commit into
supabase-community:masterfrom
fresh55:fix/postgrest-single-multirow-406

Conversation

@fresh55

@fresh55 fresh55 commented Aug 12, 2026

Copy link
Copy Markdown

Single() asked PostgREST for a single object (Accept: application/vnd.pgrst.object+json) and swallowed the resulting 406 whenever the query didn't match exactly one row, so an under-constrained query that matched several rows was indistinguishable from "not found" (#300).

This fetches a plain list instead and enforces cardinality client-side, the way postgrest-js's maybeSingle() has done since supabase/postgrest-js#361: zero rows still returns null, more than one row now throws a PostgrestException. That also drops the dependency on PostgREST's error wording.

CoercionTests' round-trip test is now scoped to the seeded row. Its unfiltered Single() was relying on the swallowed 406 whenever sibling tests had inserted extra kitchen_sink rows.

Versioning

Callers that treated null as "not found" on a query that actually matched several rows now get a PostgrestException instead. I've left the ! off the subject since the old return value was never intentional, and lockstep versioning would major-bump all seven packages for it.

Closes #300

@fresh55
fresh55 force-pushed the fix/postgrest-single-multirow-406 branch from cfe6dbe to d599508 Compare August 12, 2026 21:10
@Tr00d Tr00d self-assigned this Aug 13, 2026
…ng null

Single() asked PostgREST for a single object (Accept: application/vnd.pgrst.object+json)
and swallowed the resulting 406 whenever the query didn't match exactly one row, so an
under-constrained query that matched several rows was indistinguishable from "not found".

Fetch a plain list instead and enforce cardinality client-side, as postgrest-js's
maybeSingle() does: zero rows still returns null, more than one row now throws.

CoercionTests' round-trip test is now scoped to the seeded row. Its unfiltered Single()
was relying on the swallowed 406 whenever sibling tests had inserted extra kitchen_sink
rows.

Closes supabase-community#300
@fresh55
fresh55 force-pushed the fix/postgrest-single-multirow-406 branch from d599508 to 371a62a Compare August 18, 2026 09:00
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(postgrest): throw on multi-row result from Single() when the query unexpectedly returns more than one row [from supabase-js]

2 participants