fix(postgrest): use POST for rpc() with get:true and object args#2530
fix(postgrest): use POST for rpc() with get:true and object args#2530PedroHenrique0713 wants to merge 1 commit into
Conversation
rpc() has a guard (_hasObjectArg) that falls back to POST + JSON body when
an arg is an object or array-of-objects, since objects can't be serialized
to URL params. The guard only checked head, not get — so a call like
supabase.rpc('fn', { data: { key: 'value' } }, { get: true })
fell into the GET branch and serialized the object as [object Object] in
the URL, silently corrupting the request.
Now (head || get) triggers the POST fallback. The return=minimal Prefer
header is only set when head (get:true wants the response data back, so
it must not request a minimal response).
Validated E2E: 3/3 tests pass (wire inspection via mock fetch for the
object-arg cases; real server for the primitive-arg case). tsc clean,
prettier clean.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Description
What changed?
rpc()has a guard (_hasObjectArg) that falls back toPOST+ JSON body when an argument is an object or array-of-objects, because objects cannot be serialized into URL query params. This guard previously only checkedhead— it now checkshead || get.The
Prefer: return=minimalheader is now only set whenheadis true (aget: truecall wants the response data back, so it must not request a minimal response).Why was this change needed?
A call like:
fell into the
GETbranch because_hasObjectArgwashead && ...(false whenheadis false). The object was then serialized into the URL as[object Object]— silently corrupting the request. PostgREST would receive?data=[object Object]instead of the intended JSON body.The
head: truepath was already correct (it triggered the POST fallback and setreturn=minimal). This PR extends the same behavior toget: true, minus thereturn=minimalheader (sincegetwants the response payload).📸 Screenshots/Examples
🔄 Breaking changes
Calls with primitive args (strings, numbers, arrays of primitives) are unaffected — they still use
GETwith URL params as before.📋 Checklist
fix(postgrest): ...pnpm nx formatto ensure consistent code formatting📝 Additional notes
Validated E2E: 3/3 tests pass. The first two tests inspect the wire (method/body/headers) via a mock fetch since the test DB has no function that accepts a jsonb arg; the third test hits the real PostgREST server to confirm the primitive-arg
get: truepath is unchanged.Local checks:
jest test/rpc-get-object-args.test.ts→ 3 passed,tsc --noEmit→ clean,prettier --check→ clean.