Behaviour with POST and Accept: application/vnd.pgrst.object+json #3374
-
Environment
Description of issueFrom Singular test I see that, even if there is not return=rep, we consider a POST to create multiple objects with
as an error (406). For instance: it "raises an error when attempting to create multiple entities" $ do
request methodPost "/addresses"
[("Prefer", "tx=commit"), singular]
[json| [ { id: 200, address: "xxx" }, { id: 201, address: "yyy" } ] |]
`shouldRespondWith`
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
} I think that this is questionable. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What I find really odd about this test is this: { matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ] Wait, we say 406, which means we can't accept the contenttype that was asked for. But at the same time... we return exactly this content-type. Shouldn't we return the error message as plain Compare this to a request for |
Beta Was this translation helpful? Give feedback.
-
This was discussed/decided on #1417. From my POV, it's like HEAD, we shouldn't change behavior because there's no body returned. The server has to obey the rules of the requested representation before any preference is executed. |
Beta Was this translation helpful? Give feedback.
I'd be very surprised if the success of my POST request depended on the
Prefer: return=rep
header. Or, since this is only my preference and not strictly enforced.. if the success of my POST request depended on the server's willingness to honor myreturn=rep
preference.Thinking this further, the server would have the choice to never return a response in those cases, even if it could, just to avoid the 406 error.
This will quickly be much more complex and confusing than what we have right now.
At least the current handling is consistent.