-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [WIP] mixing offset and limit with Range header #3578
base: main
Are you sure you want to change the base?
Conversation
66629e4
to
99e4841
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all, It's looking good! Separating Range
s and treating limit
and offset
as query strings should be the right choice. I'd say 👍 on continuing with this PR.
Some considerations below:
-- Replace .offset ending with .limit to be able to match those params later in a map | ||
offsets = first (replaceLast "limit") <$> filter (endingIn ["offset"] . fst) nonemptyParams | ||
offset = lookupParam "offset" | ||
limit = lookupParam "limit" | ||
lookupParam :: Text -> Maybe Text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still allow doing something like
/clients?select=*,projects(*)&projects.limit=1
I think this change breaks that.
src/PostgREST/Error.hs
Outdated
toJSON LimitNoOrderError = toJsonPgrstError | ||
ApiRequestErrorCode09 "A 'limit' was applied without an explicit 'order'" Nothing (Just "Apply an 'order' using unique column(s)") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also may be related. It breaks limited updates/deletes which need order
to be present in the query string.
@laurenceisla @steve-chavez How should this change now reflect in it "using the Range header" $
request methodGet "/rpc/getitemrange?min=2&max=4"
(rangeHdrs (ByteRangeFromTo 1 1)) mempty
`shouldRespondWith` [json| [{"id":4}] |]
{ matchStatus = 200
, matchHeaders = ["Content-Range" <:> "1-1/*"]
}
it "using limit and offset" $ do
post "/rpc/getitemrange?limit=1&offset=1" [json| { "min": 2, "max": 4 } |]
`shouldRespondWith` [json| [{"id":4}] |]
{ matchStatus = 200
, matchHeaders = ["Content-Range" <:> "1-1/*"]
}
get "/rpc/getitemrange?min=2&max=4&limit=1&offset=1"
`shouldRespondWith` [json| [{"id":4}] |]
{ matchStatus = 200
, matchHeaders = ["Content-Range" <:> "1-1/*"] Edit: Also, now that limit and offset are separated from range header, how about we also separate their test cases? |
f2a00dc
to
cde8eb8
Compare
Not necessarily, remember that the Range can have an offset, e.g.
The entire resource (without the The other requests with
I agree, they must be separated now. |
@laurenceisla Alright, now with this, I am also assuming that |
Yes that would be correct. This will make PostgREST a bit more HTTP compliant, so this PR is also partially related to #1089. There, it mentions:
|
it "updates with limit/offset using table default values(field-with_sep) when json keys are undefined" $ do
request methodPatch "/complex_items?select=id,name&columns=name,field-with_sep&limit=1&offset=2&order=id"
[("Prefer", "return=representation"), ("Prefer", "missing=default")]
[json|{"name": "Tres"}|]
`shouldRespondWith`
[json|[
{"id":3,"name":"Tres"}
]|]
{ matchStatus = 200
, matchHeaders = ["Preference-Applied" <:> "missing=default, return=representation"]
} I am having trouble figuring out what this one test is NOW supposed to return and what could be the problem here? @laurenceisla WDYT?
|
cde8eb8
to
224bdf5
Compare
Wait, I think I made a mistake here. I mean, this is correct and needs to be changed, but it would be better to do so in a different PR. I didn't take in consideration that the Sorry about this, you made considerable changes to the tests and the process that generates the
|
224bdf5
to
225e512
Compare
225e512
to
bb9069d
Compare
@laurenceisla @steve-chavez @wolfgangwalther One test case that is remaining to be fixed is: test/spec/Feature/Query/UpdateSpec.hs:368:13:
1) Feature.Query.UpdateSpec, Patching record, PATCH with ?columns parameter, apply defaults on missing values, updates with limit/offset using table default values(field-with_sep) when json keys are undefined
body mismatch:
expected: [{"id":3,"name":"Tres"}]
but got: [] Any idea how is this test giving this result? |
This PR is too big for me to look at - I don't even know where to start. Is there any chance to somehow split this one commit into multiple pieces, where each piece can stand alone, make sense and have passing tests? |
I think not. The range header and |
Fixes #3007.
@steve-chavez @laurenceisla @wolfgangwalther This is an attempt to fix this issue. There is still a lot of refactoring and testing left in this PR. For now, I would like you to review this redesign. Am I going in the right direction with this?