Skip to content

fix(postgrest): build a valid Prefer header in select() when none is set#1433

Open
spydon wants to merge 2 commits into
chore/enable-small-safe-batchfrom
fix/postgrest-select-prefer-and-this-cleanup
Open

fix(postgrest): build a valid Prefer header in select() when none is set#1433
spydon wants to merge 2 commits into
chore/enable-small-safe-batchfrom
fix/postgrest-select-prefer-and-this-cleanup

Conversation

@spydon

@spydon spydon commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1432.

What

This came out of investigating avoid-nullable-interpolation (PR scope: only the meaningful sites — most of that rule's 80 hits are cosmetic toString/log interpolation, so the rule stays disabled). One site turned out to be a real bug:

PostgrestTransformBuilder.select() builds the Prefer header like:

if (newHeaders['Prefer'] != null) {
  newHeaders['Prefer'] = '${newHeaders['Prefer']},';
}
newHeaders['Prefer'] = '${newHeaders['Prefer']}return=representation';

The second line runs unconditionally. When no Prefer header is set yet, newHeaders['Prefer'] is null and the interpolation produces the malformed header nullreturn=representation.

insert()/update()/delete() set Prefer = '' first, so their .select() is unaffected — but rpc(...).select() does not set Prefer, so it was sending the malformed header.

Fix: default the missing value to an empty string (${newHeaders['Prefer'] ?? ''}). No change when Prefer is already set.

Also

  • Regression test in the custom-http-client group: rpc('empty-succ').select().head() now sends Prefer: return=representation (fails before this fix with nullreturn=representation).
  • Dropped two redundant this. qualifiers in postgrest.dart left over from an earlier url -> requestUrl rename.

Verification

  • New test passes with the fix, fails without it (confirmed by temporarily reverting).
  • dart analyze clean (incl. infos); dcm analyze packages -> no issues found.
  • postgrest mock suites pass.

Note: avoid-nullable-interpolation itself remains disabled (the toString/log majority would still violate it).

PostgrestTransformBuilder.select() appended 'return=representation' to
the existing Prefer value, but when no Prefer header was set yet (e.g.
rpc(...).select()) it interpolated the null value and produced the
malformed header 'nullreturn=representation'. Default the missing value
to an empty string. Adds a regression test, and drops two redundant
this. qualifiers left by an earlier rename.
@spydon spydon requested a review from a team as a code owner June 17, 2026 13:25
@github-actions github-actions Bot added the postgrest This issue or pull request is related to postgrest label Jun 17, 2026
…ment

Compose the Prefer header from a list joined by commas instead of a
conditional prepend followed by a second assignment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postgrest This issue or pull request is related to postgrest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants