Skip to content

Commit

Permalink
fixing issue in context manager to avoid some noice in query history
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mrojas committed Jul 5, 2024
1 parent f58ea1e commit 9aa46e0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions extras/context_helper/sfpark_contextmanager.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import logging

class SessionContextManager:
def __init__(self, builder_object):
self.builder_object = builder_object
self.session = None
def __init__(self, session):
self.session = session

def __enter__(self):
self.session = self.builder_object.create()
self.session.sql('BEGIN').collect()
self.session.connection.cursor().execute('BEGIN')
print("BEGIN")
return self.session

def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
print("ERROR==>",exc_val)
logging.error(exc_val)
self.session.sql('ROLLBACK').collect()
self.session.connection.cursor().execute('ROLLBACK')
print("ROLLBACK")
return True
else:
self.session.sql('COMMIT').collect()
self.session.close()
self.session.connection.cursor().execute('COMMIT')
print("COMMIT")

0 comments on commit 9aa46e0

Please sign in to comment.