Skip to content

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

@elyobo

Description

@elyobo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions