Skip to content

parity(postgrest): throw on multi-row result from Single() when the query unexpectedly returns more than one row [from supabase-js] #300

Description

@grdsdev

Warning

Auto-generated parity issue — may be a false positive.

This issue was created automatically by /sync-sdk-parity from a heuristic
analysis of recent supabase-js commits. The tooling has limited insight
into language-specific idioms and may have:

  • misidentified a JS-only change as cross-language relevant,
  • missed an existing implementation in this SDK under a different name,
  • or proposed an API shape that doesn't fit this language's conventions.

It is the SDK author's responsibility to validate the need before
implementing.
If this change does not apply to this SDK, please close the
issue with a short note explaining why.


SDK Parity: C# implementation needed

A change was made in supabase-js that needs to be implemented in this repository for SDK parity.

Reference Implementation (supabase-js)

What Changed

When a query requests a single row (Accept: application/vnd.pgrst.object+json) and the query unexpectedly matches more than one row, PostgREST responds 406 Not Acceptable. Previously supabase-js's PostgrestBuilder swallowed this and returned data: null even when throwOnError was enabled — silently hiding a real bug (the query should have been scoped to return one row). Now, when throw-on-error is enabled, this case throws a PostgrestError instead of silently returning null.

Code Reference

if (this.shouldThrowOnError) {
  // hint is null in the returned error to match PostgREST
  throw new PostgrestError({ ...error, hint: error.hint ?? '' })
}

Implementation Guidance

Expected API Surface

postgrest-csharp's Table.cs Single() (around line 613) catches PostgrestException and returns null whenever StatusCode == HttpStatusCode.NotAcceptable (406), per prior investigation — this doesn't distinguish the zero-rows case (expected, should return null) from the multi-row case (a bug, should throw). Fix Single() to only swallow the zero-rows variant of the 406 response and rethrow on the multi-row variant (may require inspecting the PostgREST error body's details/message to distinguish the two cases, matching what supabase-js's fix does).

Key Behaviors to Match

Zero rows still returns null (unchanged) · Multiple rows throws a PostgrestException instead of silently returning null

Acceptance Criteria

  • Feature/fix implemented matching supabase-js behavior
  • Public API follows C# naming conventions and idioms
  • Unit tests cover happy path and edge cases
  • Documentation updated
  • No breaking changes to existing API (or clearly documented)

Context

  • supabase-js version: v3.0.0-next.29
  • Parity tracking: This issue was auto-generated by SDK parity analysis

Generated with Claude Code /sync-sdk-parity

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions