-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing issue in context manager to avoid some noice in query history
- Loading branch information
1 parent
f58ea1e
commit 9aa46e0
Showing
1 changed file
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |