Supabase 'infinite recursion' error from circular RLS policies, and how to fix it
A common Supabase problem appears when adding sharing, teams, or admin roles: pages that previously loaded return an 'infinite recursion detected in policy' error with code 42P17. The cause is row-level security policies that query the same table they protect, or two tables whose policies reference each other, forcing PostgreSQL into an endless evaluation loop. The author tested this against PostgreSQL 16.15 and notes the error can name the wrong table and may not reproduce in the SQL Editor, which bypasses policies for the table owner. The recommended fix is moving the lookup logic into a SECURITY DEFINER function in a private schema, which runs with privileges that skip the recursive policy check. Example functions and rewritten policies are provided for both the single-table admin case and the two-table sharing case.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in