Skip to content

"infinite recursion detected in policy" #3328

Answered by soedirgo
tconroy asked this question in Questions
Discussion options

You must be logged in to vote

You can try using a function that bypasses RLS:

-- Parameters need to be prefixed because the name clashes with `om`'s columns
CREATE FUNCTION is_member_of(_user_id uuid, _organization_id uuid) RETURNS bool AS $$
SELECT EXISTS (
  SELECT 1
  FROM organization_memberships om
  WHERE om.organization_id = _organization_id
  AND om.user_id = _user_id
);
$$ LANGUAGE sql SECURITY DEFINER;
-- Function is owned by postgres which bypasses RLS

Then in the policy definition:

is_member_of(auth.uid(), organization_id)

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@tconroy
Comment options

@malalecherocks
Comment options

@zalito12
Comment options

Answer selected by soedirgo
Comment options

You must be logged in to vote
1 reply
@szuliq
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants