Skip to content

Commit

Permalink
SQL: mess around with ensure_tx contextmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Aug 9, 2023
1 parent 33e5456 commit 84600b6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions nomenklatura/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ def get_metadata() -> MetaData:

@contextmanager
def ensure_tx(conn: Connish = None) -> Generator[Connection, None, None]:
if conn is not None:
yield conn
return
engine = get_engine()
with engine.begin() as conn:
yield conn
try:
if conn is not None:
yield conn
else:
engine = get_engine()
with engine.begin() as conn:
yield conn
finally:
if conn is not None:
conn.commit()

0 comments on commit 84600b6

Please # to comment.