Skip to content
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

nightly: Requests no longer return single-element array by default for single object return functions #1849

Closed
W1M0R opened this issue May 13, 2021 · 2 comments

Comments

@W1M0R
Copy link

W1M0R commented May 13, 2021

Environment

  • PostgreSQL version: 12.6
  • PostgREST version: nightly-2021-03-05-19-03-d3a8b5f
  • Operating system: Ubuntu

Description of issue

Consider the following function, that gets exposed as /rpc/login:

create or replace function public.login(options my_types.login_options) returns my_types.login_result as

In 7.0.1, this function would return a JSON array with a single element, and clients had to opt-in using 'Accept: application/vnd.pgrst.object+json'. Using nightly-2021-03-05-19-03-d3a8b5f, this function now returns a single object, that is, not a JSON array. I can't seem to opt-out of that. Although returning a single object makes more sense, unfortunately clients of the API already expect a single element JSON array, so an upgrade to the next PostgREST version would be a breaking change for clients.

Consider whether it may be helpful to enable/disable that functionality via the postgrest.conf file, or via some other method (perhaps on a per-function basis, e.g. it would be great to disable the new functionality for stable endpoints such as /v1/login, but use the new default for newly added endpoints).

#1779

@wolfgangwalther
Copy link
Member

Yes, that's on purpose. It will be listed as a breaking change for the next release. I don't think we'll provide a way to opt out of that.

If you don't want to change your clients for now, you can just mark your function's return type as returns setof my_types.login_result - but still only return one row. This will give you the same one-element-array - in both the current and the next release.

@W1M0R
Copy link
Author

W1M0R commented May 14, 2021

Thank you very much for the workaround @wolfgangwalther, that should solve my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants