-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix wrong status 404 when PATCH request didn't change anything #1272
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 wrong status 404 when PATCH request didn't change anything #1272
Conversation
Added a few changes: Using a empty payload no longer touches the db. They keep returning the same status as before. 1º was a necessary condition for 2º, because we need to distinguish between, declaring no changes and not founding records to change, which return different status codes. What do you think? |
Yes. This is correct 👍 However, the wildcard pattern matchs are a bit hard to follow. I think not hitting the database should not be a concern for now and the code can be a bit more concise(the added variables are good though). It could be something like: let
contentRangeHeader = contentRangeH 0 (toInteger $ queryTotal - 1)
(toInteger <$> if shouldCount then Just queryTotal else Nothing)
minimalHeaders = [contentRangeHeader]
fullHeaders = toHeader contentType : minimalHeaders
updateIsNoOp = S.null $ pjKeys pJson
status | queryTotal == 0 && not updateIsNoOp = status404
| iPreferRepresentation apiRequest == Full = status200
| otherwise = status204
return $ if iPreferRepresentation apiRequest == Full
then responseLBS status fullHeaders (toS body)
else responseLBS status minimalHeaders mempty |
A few more commits.
|
Additional commit for some whitespace. I think it reads better. |
Further commit that fixes the issue mentioned above. I've also hardcoded the tests, so it doesn't only check if it is an error, but which as well. Curious thing happened on |
@Qu4tro Thank you! Sorry the review took so long. |
This partially reverts PostgREST#1257 / PostgREST#1272 / 5535317 where the 404 was introduced. A 406 error is still returned when requesting a single object via accept header. Returning an error when no rows are changed can be introduced through a different syntax again, see the discussion in PostgREST#2164. Fixes PostgREST#2343 Signed-off-by: Wolfgang Walther <[email protected]>
This partially reverts PostgREST#1257 / PostgREST#1272 / 5535317 where the 404 was introduced. A 406 error is still returned when requesting a single object via accept header. Returning an error when no rows are changed can be introduced through a different syntax again, see the discussion in PostgREST#2164. Fixes PostgREST#2343 Signed-off-by: Wolfgang Walther <[email protected]>
This partially reverts #1257 / #1272 / 5535317 where the 404 was introduced. A 406 error is still returned when requesting a single object via accept header. Returning an error when no rows are changed can be introduced through a different syntax again, see the discussion in #2164. Fixes #2343 Signed-off-by: Wolfgang Walther <[email protected]>
This is a simple attempt to fix the reported bug described in title.
So, citing #1257 and confirmed by this test in this PR:
This PR can be tweaked to take care of some of the failing tests, but like in the previous PR, I would argue that some of those failing tests should be tweaked as well.
Let me know what you think.
This resolves #1257 .