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

rpc + custom type argument + count + head fails with bad request #583

Open
2 tasks done
elyobo opened this issue Dec 10, 2024 · 0 comments
Open
2 tasks done

rpc + custom type argument + count + head fails with bad request #583

elyobo opened this issue Dec 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@elyobo
Copy link

elyobo commented Dec 10, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I have a function which accepts an object custom type as an argument. I can invoke it with e.g.

supabase.rpc('my_function', { some_arg: { whatever: 'here' } })

but if I try to get a count without a body, e.g.

supabase.rpc('my_function', { some_arg: { whatever: 'here' } }, { count: 'exact', head: true })

then it fails, because

  1. specifying head causes a HEAD request to be sent, ant
  2. HEAD requests can't have bodies, so
  3. PostgrestClient adds it to the URL search params which does not serialize it correctly

I'm not familiar with Postgrest outside of Supabase, but looking at the docs I can't see a valid way to serialize the body into the URL (and that might have URL length issues anyway), but it seems like we could send a POST request with return=minimal in the prefer header to achieve a similar result as an alternative. I'm not clear on whether there's any internal difference in what Postgrest actually executes internally in HEAD vs return=minimal.

Changing the logic in PostgrestClient adds it to the URL search params to send a POST + return=minimal for head requests looks straightforward but may have implications I don't understand - and elsewhere in the client the return=representation looks to be hard coded anyway, overwriting custom headers set there.

Workarounds include

  • just get the full payload as well as the count (head: false)
  • add a separate RPC which invokes the original RPC and just returns the count instead, and invoke that
  • refactor the RPC to take scalar args instead of a custom type

To Reproduce

See issue description.

Expected behavior

Supabase client should at least clearly indicate that this invocation cannot be done by identifying object types in the args when adding them to the url search params; ideally it should just work, however, e.g. using the return=minimal header to support this scenario.

Screenshots

N/A

System information

Not relevant.

Additional context

Add any other context about the problem here.

@elyobo elyobo added the bug Something isn't working label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant