Skip to content

Commit e570710

Browse files
committed
close sqlite3 connection
1 parent 8c20182 commit e570710

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

synapseclient/models/services/migration.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,9 @@ async def index_files_for_migration_async(
754754
db_path = _get_default_db_path(entity_id)
755755

756756
# Initialize database
757-
with sqlite3.connect(db_path) as conn:
758-
cursor = conn.cursor()
757+
conn = sqlite3.connect(db_path)
758+
cursor = conn.cursor()
759+
try:
759760
_ensure_schema(cursor)
760761
_prepare_migration_db(
761762
conn=conn,
@@ -767,25 +768,27 @@ async def index_files_for_migration_async(
767768
file_version_strategy=file_version_strategy,
768769
include_table_files=include_table_files,
769770
)
770-
try:
771-
await _index_entity_async(
772-
conn=conn,
773-
cursor=cursor,
774-
entity=entity,
775-
parent_id=None,
776-
dest_storage_location_id=dest_storage_location_id,
777-
source_storage_location_ids=source_storage_location_ids,
778-
file_version_strategy=file_version_strategy,
779-
include_table_files=include_table_files,
780-
continue_on_error=continue_on_error,
781-
synapse_client=client,
782-
)
783-
except IndexingError as ex:
784-
client.logger.exception(
785-
f"Aborted due to failure to index entity {ex.entity_id} of type {ex.concrete_type}. "
786-
"Use continue_on_error=True to skip individual failures."
787-
)
788-
raise ex.__cause__
771+
try:
772+
await _index_entity_async(
773+
conn=conn,
774+
cursor=cursor,
775+
entity=entity,
776+
parent_id=None,
777+
dest_storage_location_id=dest_storage_location_id,
778+
source_storage_location_ids=source_storage_location_ids,
779+
file_version_strategy=file_version_strategy,
780+
include_table_files=include_table_files,
781+
continue_on_error=continue_on_error,
782+
synapse_client=client,
783+
)
784+
except IndexingError as ex:
785+
client.logger.exception(
786+
f"Aborted due to failure to index entity {ex.entity_id} of type {ex.concrete_type}. "
787+
"Use continue_on_error=True to skip individual failures."
788+
)
789+
raise ex.__cause__
790+
finally:
791+
conn.close()
789792

790793
return MigrationResult(db_path=db_path, synapse_client=client)
791794

0 commit comments

Comments
 (0)