Skip to content

Commit 1a9811e

Browse files
committed
close sqlite connection
1 parent e570710 commit 1a9811e

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

synapseclient/models/services/migration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,9 @@ async def migrate_indexed_files_async(
14061406
client = Synapse.get_client(synapse_client=synapse_client)
14071407

14081408
# Retrieve settings
1409-
with sqlite3.connect(db_path, check_same_thread=False) as conn:
1410-
cursor = conn.cursor()
1409+
conn = sqlite3.connect(db_path, check_same_thread=False)
1410+
cursor = conn.cursor()
1411+
try:
14111412
_ensure_schema(cursor)
14121413
existing_settings = _retrieve_index_settings(cursor)
14131414
if existing_settings is None:
@@ -1436,6 +1437,8 @@ async def migrate_indexed_files_async(
14361437
synapse_client=client,
14371438
)
14381439
return MigrationResult(db_path=db_path, synapse_client=client)
1440+
finally:
1441+
conn.close()
14391442

14401443

14411444
async def _execute_migration_async(

tests/unit/synapseclient/services/unit_test_migration_and_types_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,13 +2348,16 @@ async def test_returns_none_when_migration_not_confirmed(
23482348
):
23492349
path, _ = db_file_with_settings
23502350
# Add an indexed row so there's something to confirm
2351-
with sqlite3.connect(path) as conn:
2351+
conn = sqlite3.connect(path)
2352+
try:
23522353
cursor = conn.cursor()
23532354
cursor.execute(
23542355
"INSERT INTO migrations (id, type, status) VALUES (?, ?, ?)",
23552356
("syn3", MigrationType.FILE.value, MigrationStatus.INDEXED.value),
23562357
)
23572358
conn.commit()
2359+
finally:
2360+
conn.close()
23582361

23592362
client = _make_mock_client()
23602363
with (

0 commit comments

Comments
 (0)