Skip to content

Commit

Permalink
refactor: removed try catch blocks
Browse files Browse the repository at this point in the history
Co-authored-by: Omar Fahmy <[email protected]>
  • Loading branch information
Ghaithq and Ofahmy143 committed Oct 6, 2024
1 parent 78df511 commit 897ed6e
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions rls/rls_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ def __enter__(self):
If the command fails, rollback the transaction.
"""
self.session._rls_bypass = True
try:
# Disable row-level security
self.session.execute(text("SET LOCAL rls.bypass_rls = true;"))
except Exception:
self.session._rls_bypass = False # Disable bypass flag to avoid issues

# Rollback transaction to avoid failed state
self.session.rollback()
raise # Re-raise the exception to stop further execution
# Disable row-level security
self.session.execute(text("SET LOCAL rls.bypass_rls = true;"))
return self.session

def __exit__(self, exc_type, exc_val, exc_tb):
Expand All @@ -88,12 +81,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
self.session.rollback()
return
try:
# Re-enable row-level security
self.session.execute(text("SET LOCAL rls.bypass_rls = false;"))
except Exception:
# Optionally rollback if there's a failure
self.session.rollback()
self.session.execute(text("SET LOCAL rls.bypass_rls = false;"))

def execute(self, *args, **kwargs):
return self.session.execute(*args, **kwargs)

0 comments on commit 897ed6e

Please sign in to comment.