
Supabase .maybeSingle() returns null with multiple rows, and it won't tell you why
The problem You query Supabase with .maybeSingle() , get null back, and assume the row doesn't exist. It does. There are actually three of them. Your app just silently moved on. Technical context When building ReadyToRelease , I had a query that checked whether a user already had an active research session before creating a new one. Classic "upsert-like" logic: if it exists, return it; if not, create it. I trusted .maybeSingle() to handle the "maybe it's there, maybe it's not" case cleanly. It does, but only if your data is clean. The moment you have duplicate rows matching your filter, .maybeSingle() doesn't throw. It doesn't warn. It returns null , exactly like it would if nothing matched. This is documented behavior. But it's the kind of thing you only truly understand after it burns you in production. The broken code const { data , error } = await supabase . from ( ' research_sessions ' ) . select ( ' * ' ) . eq ( ' user_id ' , userId ) . eq ( ' status ' , ' active ' ) . maybeSingl
Continue reading on Dev.to JavaScript
Opens in a new tab




