Skip to content

Commit 78027af

Browse files
author
Neil Muller
committed
Add explicit connection cleanup
Python 3.11 tweaked how the sqlite module worked, which changed the implicit cleanup behavior, which can cause problems on windows when temporary files are involved. See the discussion in python/cpython#97641 The cursor juggling code in the database upgrade test implicitly relied on this, so we need to tweak the logic so we explicitly close the connection so the tests pass on Windows again.
1 parent 342a8a5 commit 78027af

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎sutekh/sutekh/tests/core/test_DatabaseUpgrade.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,10 +1679,12 @@ def test_upgrade_old_version(self):
16791679
oOldDB = connectionForURI("sqlite://%s" % sDbFile)
16801680
sqlhub.processConnection = oOldDB
16811681

1682-
oCursor = oOldDB.getConnection().cursor()
1682+
oCursorConn = oOldDB.getConnection()
1683+
oCursor = oCursorConn.cursor()
16831684
for sSQL in OLD_VERSION_DUMP:
16841685
oCursor.execute(sSQL)
16851686
oCursor.close()
1687+
oOldDB.releaseConnection(oCursorConn)
16861688

16871689
# Assert that the versions fail
16881690
oVer = DatabaseVersion(oConn=oOldDB)
@@ -1728,20 +1730,23 @@ def test_upgrade_old_version(self):
17281730
assert oDefJyhad
17291731
assert IPhysicalCard((oMagnum, oDefJyhad))
17301732

1733+
oVer.expire_cache()
1734+
oVer.expire_table_conn(oOldDB)
17311735
oOldDB.close()
17321736

17331737
# Restore old state
1734-
oVer.expire_cache()
17351738
sqlhub.processConnection = oConn
17361739
oConn.cache.clear()
17371740
aTables.reverse()
17381741
for cCls in aTables:
17391742
cCls.dropTable(ifExists=True, connection=oConn)
17401743

1741-
oCursor = oConn.getConnection().cursor()
1744+
oCursorConn = oConn.getConnection()
1745+
oCursor = oCursorConn.cursor()
17421746
for sSQL in aCurData:
17431747
oCursor.execute(sSQL)
17441748
oCursor.close()
1749+
oConn.releaseConnection(oCursorConn)
17451750
oConn.cache.clear()
17461751
init_cache()
17471752

0 commit comments

Comments
 (0)