You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(postgrest): replace earlier preferences in maxAffected - #2844
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.
Real PostgREST 16.5, delete over 3 rows with .maxAffected(10).maxAffected(1): master deletes all 3, this branch returns PGRST124 and keeps them.
🔄 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.
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.
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>
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.
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>
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
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
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.
🔍 Description
What changed?
maxAffected()now removes earlierhandlingandmax-affectedvalues fromPreferbefore 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-levelhandling=lenientturned 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 returnsPGRST124and keeps them.🔄 Breaking changes
One behavior changes on purpose. With a client header
Prefer: handling=lenient, foo=bar, PostgREST used lenient handling and ignored bothfoo=barand the limit. Now the header isfoo=bar, handling=strict, max-affected=1, so PostgREST rejects the unknownfoo=barwithPGRST122instead of running an unlimited delete. That is what strict handling means.📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
test/max-affected.test.ts: header tests for two calls in a row, a clienthandling(with and without spaces) andselect()between two calls fail on master and pass here. A header test checks thatcountstays. A PostgREST-backed test deletes with.maxAffected(10).maxAffected(1)and expectsPGRST124.type-checkandtype-check:testpass for postgrest-js.maxAffected()now says it replaces an earlierhandlingpreference.🤖 Generated with Claude Code