Skip to content

fix(postgrest): replace earlier preferences in maxAffected - #2844

Open
Brian-1812 wants to merge 6 commits into
supabase:masterfrom
Brian-1812:fix/postgrest-max-affected-override
Open

Brian-1812 wants to merge 6 commits into
supabase:masterfrom
Brian-1812:fix/postgrest-max-affected-override

Conversation

@Brian-1812

@Brian-1812 Brian-1812 commented Nov 11, 2026 •

Copy link
Copy Markdown

🔍 Description

What changed?

maxAffected() now removes earlier handling and max-affected values from Prefer before it adds its own. Other preferences stay.

Why was this change needed?

PostgREST uses the first value of a repeated preference. So .maxAffected(10).maxAffected(1) kept 10, and a client-level handling=lenient turned the limit off. Both cases could delete more rows than the caller allowed. supabase-py fixed the same bug in supabase/supabase-py#1827.

Closes #2842

📸 Screenshots/Examples

Real PostgREST 16.5, delete over 3 rows with .maxAffected(10).maxAffected(1): master deletes all 3, this branch returns PGRST124 and keeps them.

master vs branch on a real PostgREST

🔄 Breaking changes

  • This PR contains no breaking changes

One behavior changes on purpose. With a client header Prefer: handling=lenient, foo=bar, PostgREST used lenient handling and ignored both foo=bar and the limit. Now the header is foo=bar, handling=strict, max-affected=1, so PostgREST rejects the unknown foo=bar with PGRST122 instead of running an unlimited delete. That is what strict handling means.

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run pnpm nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

📝 Additional notes

  • test/max-affected.test.ts: header tests for two calls in a row, a client handling (with and without spaces) and select() between two calls fail on master and pass here. A header test checks that count stays. A PostgREST-backed test deletes with .maxAffected(10).maxAffected(1) and expects PGRST124. type-check and type-check:test pass for postgrest-js.
  • The TSDoc of maxAffected() now says it replaces an earlier handling preference.

🤖 Generated with Claude Code

maxAffected() appended `handling=strict` and `max-affected` to the
Prefer header. PostgREST uses the first value of a repeated preference.
So `.maxAffected(10).maxAffected(1)` kept the limit of 10, and a
client-level `handling=lenient` turned the limit off.

Remove earlier `handling` and `max-affected` values before adding the
new ones. Other preferences stay in their order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ecd507ff-6d6c-4c12-a8bb-353cb885ecef
Commits

Reviewing files that changed from the base of the PR and between cf1ab4a and 7effd04.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • When multiple affected-row limits are set, the latest limit now takes effect, including when set after selecting returned data.
    • Other request preferences are preserved when the limit changes.
    • Requests that exceed the latest limit are rejected, and unknown preferences are handled strictly.

maxAffected now removes existing handling= and max-affected= preferences before setting handling=strict and the requested limit. Tests cover repeated calls, preservation of other preferences, and a delete that exceeds the latest limit.

Assessment against linked issues

Objective Addressed Explanation
Replace earlier max-affected and handling preferences so the latest limit applies, including when the client sets handling=lenient [#2842] ✅

Possibly related issues

  • supabase/supabase-js issue 2834 — The PR changes how maxAffected() sets preferences, but it does not change maybeSingle() or its Accept header handling, so it does not address the reported behavior.

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · previous review ea00e

maxAffected now applies the latest limit even when earlier calls or client headers set conflicting preferences. Tests cover the header and the delete failure. No merge-blocking risk was identified.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b339951b-76ec-4ef0-a609-5f63b9e9da30
Commits

Reviewing files that changed from the base of the PR and between 6964595 and ea00e21.

Files selected for processing: 2

  • packages/core/postgrest-js/src/PostgrestTransformBuilder.ts
  • packages/core/postgrest-js/test/max-affected.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

…e header shapes

Add a PostgREST-backed delete test for .maxAffected(10).maxAffected(1),
header tests for a client Prefer without spaces, select() between two
calls, and rpc() with count. Document that maxAffected replaces a
client-level handling preference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brian-1812
Brian-1812 marked this pull request as ready for review November 12, 2026 01:41
@Brian-1812
Brian-1812 requested review from a team as code owners November 12, 2026 01:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brian-1812

Copy link
Copy Markdown
Author

Merged the latest master. Could a maintainer approve the fork workflows so CI can run?

@pkg-pr-new

pkg-pr-new Bot commented Nov 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2844

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2844

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2844

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2844

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2844

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2844

commit: 7effd04

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 94.645% — Brian-1812:fix/postgrest-max-affected-override into supabase:master. No base build found for supabase:master.

This branch has not been deployed

No deployments
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.

postgrest-js: maxAffected() keeps an earlier limit or a lenient handling preference

2 participants