fix(postgrest): override limit and offset instead of appending duplicates#1512
Open
AndroidPoet wants to merge 1 commit into
Open
fix(postgrest): override limit and offset instead of appending duplicates#1512AndroidPoet wants to merge 1 commit into
AndroidPoet wants to merge 1 commit into
Conversation
8ead7c7 to
9cbbe03
Compare
…ates limit() and range() built their query params with appendSearchParams, so chaining or re-applying them on a shared builder emitted duplicate, single-valued params, e.g. select().limit(5).range(0,9) produced limit=5&limit=10&offset=0 and limit(1).limit(2) produced limit=1&limit=2. PostgREST treats limit/offset as single-valued, so override them (last call wins), matching postgrest-js and the select()/order() handling in the same file.
9cbbe03 to
e4b5a19
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
limit()andrange()built their query params withappendSearchParams, which accumulates repeated keys. Becauselimitandoffsetare single-valued in PostgREST, chaining or re-applying them emitted duplicate, conflicting params:This overrides those keys so the last call wins.
Why
limit/rangeusedappendSearchParams, butselect(postgrest_transform_builder.dart:46) andorder(:88) in the same file already useoverrideSearchParamsfor exactly this reason. postgrest-js also usessearchParams.set(...)forlimitandrange. Emitting twolimit/offsetvalues is ambiguous and diverges from both.Fix: give
overrideSearchParamsthe same optional[Uri? url]parameter thatappendSearchParamsalready has, then use it forlimit(single key) andrange(bothoffsetandlimit).Not a breaking change
A single
limit()/range()call produces the same query string as before — only the previously-duplicated case changes (the last value now wins, which is the documented intent).overrideSearchParamsgains an optional parameter, so existing callers are unaffected.Tests
Added
packages/postgrest/test/limit_range_test.dart(URL-capturing mock):.limit(1).limit(2)→limit=2;.limit(5).range(0,9)→ singlelimit=10+offset=0;.range(0,9).range(10,19)→ singleoffset=10/limit=10; and thereferencedTablevariant stays scoped and single-valued. All fail on the current code (e.g.Actual: ['1', '2']) and pass with the fix.dart formatanddart analyze --fatal-warningsare clean.