File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,17 +43,17 @@ def with_rls_context
4343 end
4444
4545 yield
46+
47+ # Reset PostgreSQL variables within the same transaction
48+ begin
49+ connection . execute ( 'RESET app.current_user_id;' )
50+ connection . execute ( 'RESET app.current_organization_id;' )
51+ connection . execute ( 'RESET app.user_role;' )
52+ rescue ActiveRecord ::StatementInvalid
53+ # Ignore reset errors
54+ end
4655 end
4756 ensure
48- # Reset PostgreSQL variables
49- begin
50- ActiveRecord ::Base . connection . execute ( 'RESET app.current_user_id;' )
51- ActiveRecord ::Base . connection . execute ( 'RESET app.current_organization_id;' )
52- ActiveRecord ::Base . connection . execute ( 'RESET app.user_role;' )
53- rescue ActiveRecord ::StatementInvalid
54- # Connection might be closed, ignore
55- end
56-
5757 # Reset thread-local variables
5858 Thread . current [ :current_organization_id ] = nil
5959 Thread . current [ :current_user_id ] = nil
You can’t perform that action at this time.
0 commit comments