Skip to content

Commit

Permalink
Revert ensure_tx function to original
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Aug 20, 2023
1 parent 5d9dd5a commit f968f90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 6 additions & 10 deletions nomenklatura/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ def get_statement_table() -> Table:

@contextmanager
def ensure_tx(conn: Connish = None) -> Generator[Connection, None, None]:
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()
if conn is not None:
yield conn
return
engine = get_engine()
with engine.begin() as conn:
yield conn


@cache
Expand Down
2 changes: 2 additions & 0 deletions nomenklatura/store/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def flush(self) -> None:
)
with ensure_tx(self.store.engine.connect()) as conn:
conn.execute(stmt)
conn.commit()
self.batch = set()
self.batch_size = 0

Expand All @@ -129,6 +130,7 @@ def pop(self, entity_id: str) -> List[Statement]:
statements: List[Statement] = list(self.store._iterate_stmts(q))
with ensure_tx(self.store.engine.connect()) as conn:
conn.execute(q_delete)
conn.commit()
return statements


Expand Down

0 comments on commit f968f90

Please sign in to comment.