Skip to content

Conversation

@7ttp
Copy link
Contributor

@7ttp 7ttp commented Dec 29, 2025

fixes object args being serialized as [object Object] when using rpc() with head: true

when head: true is used with object type arguments, the client now uses POST with Prefer: return=minimal header instead of HEAD, since HEAD requests cannot have a body and objects cannot be properly serialized to URL params.

closes supabase/supabase#41641

@7ttp 7ttp requested review from a team as code owners December 29, 2025 19:19
Copy link
Contributor

@mandarini mandarini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Contributor

@mandarini mandarini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix @7ttp! Please add a test to prevent regression. Here's a suggested approach using mock fetch:

  // In packages/core/postgrest-js/test/fetch-errors.test.ts or new file

  test('rpc with head: true and object args uses POST with return=minimal', async () => {
    const mockFetch = jest.fn().mockResolvedValue({
      ok: true,
      status: 200,
      statusText: 'OK',
      headers: new Headers(),
      json: async () => null,
      text: async () => '',
    })

    const postgrest = new PostgrestClient<Database>('https://example.com', {
      fetch: mockFetch as any,
    })

    await postgrest.rpc('my_func', { obj_arg: { nested: 'value' } }, { head: true })

    const [url, options] = mockFetch.mock.calls[0]
    expect(options.method).toBe('POST')
    expect(JSON.parse(options.body)).toEqual({ obj_arg: { nested: 'value' } })
    expect(options.headers.get('Prefer')).toContain('return=minimal')
  })

Once added, this looks good to merge!

@7ttp 7ttp requested a review from mandarini January 6, 2026 07:02
@mandarini mandarini merged commit 0737918 into supabase:master Jan 7, 2026
27 checks passed
@7ttp 7ttp deleted the fix/rpc-obj branch January 7, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpc() with head:true and object arguments serializes as [object Object]

2 participants