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
Output error when doing GET with plurality=singular and more than one row is returned #748
Comments
We had discussed that behavior in the original pull request (this comment). Your proposal is behavior number 2 from that discussion. It looks like we chose behavior 1 only for expediency. I understand why it would be helpful to do things the way you propose. Thinking about it again, if we want to raise errors when a client asks for a singular response to a resource with multiple rows then we're technically not talking about a client preference, but more properly an expectation. RFC7240 says, "The Prefer request header field is used to indicate that particular server behaviors are preferred by the client but are not required for successful completion of the request." Whereas RFC2616 says, "The Expect request-header field is used to indicate that particular server behaviors are required by the client." So here's my proposal:
My one concern about the Expect header at this point is this comment:
|
I've been testing sending an Expect header to postgREST through nginx 1.10.1, and nginx doesn't proxy pass that particular header even with the This article http://www.fallingcanbedeadly.com/posts/http-100-continue-latency-and-you also points that nginx behaves this way. Also from the code https://github.com/nginx/nginx/blob/master/src/http/modules/ngx_http_proxy_module.c#L1938 I think something can be intuited. Though to confirm this I'd have to compile nginx with debug logs enabled. |
@steve-chavez wow, good catch |
Hm, good research. That's too bad about the lack of HTTP support. This is a perplexing issue, I've had a few more thoughts about the semantics. Now is a good time to figure it out so we can do the right thing in the big release.
I'm curious what you think of this. Here is an article about the structure of mime types and how to make new ones. Technically what I wrote above with the We could also continue using the Prefer header but remove the server side errors. The client would discover that the resource is plural because it would get back an array instead of an object... |
What is the reason for suppressing the According to that restriction getting the total count from |
Actually what do you all think about removing the plurality=singular behavior for the 0.4 release and investigating a new mime type for a future release like 0.4.1? |
@begriffs Regarding your proposal, if we were to keep For me the I don't think that removing the feature is the best solution for the users, maybe we could leave just like it is or how about just agreeing on a mime type now and applying it. I guess we could also ignore the IANA requirement for now, I've seen an unregistered |
I'll +1 the option of having the type=object mime-type. That would be easy enough to implement on the client side. |
A quick side note: the issue of what to do with multiple rows with |
I think the handling=strict is a good option until the mime type is settled. Seeing that the only postgREST Prefer value that has a potential error condition is |
postgREST current behavior is to do a
LIMIT 1 OFFSET 0
when doing a GET withplurality=singular
, I think it will be more appropriate to give an error when more than one row would be returned.This would help with client errors, for example a while back I got a case of a duplicate key and postgREST could have helped me there since I mostly use
plurality=singular
when explicitly requesting a single row with filters or a limit.Also this would be a more consistent behavior since POST and PATCH already give an error when returning more than one mutated row.
The text was updated successfully, but these errors were encountered: