Reversal runs twice when two requests race
SupabaseLikely fix
Postgres RPC
There is no error message for this one, only the symptom in the title.
Cause
The idempotency guard read "already reversed?" and then inserted. Two callers could both pass the check before either wrote.
Fix
Move check and insert into one database function that holds the same per-user advisory lock as the spend path (pg_advisory_xact_lock). A unique index only works if there is exactly one valid row per key.
More Supabase errors
- Supabase .single() fails with PGRST116 for a row you know exists{"code": "PGRST116", "details": "The result contains 0 rows", "message": "JSON object requested, multiple (or no) rows returned"}
- PostgREST 500: canceling statement due to statement timeout on a jsonb filtercode: 57014, message: 'canceling statement due to statement timeout'