Skip to content

Commit 6c3491d

Browse files
author
chenyunliang520
committed
Add transaction rollback and safe connection closure in fix_db.py
1 parent 1f8a952 commit 6c3491d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/fix_db.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,16 @@ def conn(conn_cls, dsn, request, tracefile):
210210
conn = conn_cls.connect(dsn)
211211
with maybe_trace(conn.pgconn, tracefile, request.function):
212212
yield conn
213-
conn.close()
213+
try:
214+
if getattr(conn, "in_transaction", False):
215+
conn.rollback()
216+
except Exception:
217+
pass
218+
finally:
219+
try:
220+
conn.close()
221+
except Exception:
222+
pass
214223

215224

216225
@pytest.fixture(params=[True, False], ids=["pipeline=on", "pipeline=off"])

0 commit comments

Comments
 (0)