Skip to content

Commit 69e0a1b

Browse files
committed
Defer truncate_tables commit in the local-dir CBS import path.
1 parent 994fdf1 commit 69e0a1b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

anyway/parsers/cbs/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ def _import_from_local_dir(batch_size):
11181118
dir_list = glob.glob("{0}/*/*".format(dir_name))
11191119

11201120
if import_ui.is_delete_all():
1121-
truncate_tables(db, (Vehicle, Involved, AccidentMarker))
1121+
truncate_tables(db, (Vehicle, Involved, AccidentMarker), commit=False)
11221122

11231123
total = 0
11241124
for directory in sorted(dir_list, reverse=False):

anyway/utilities.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ def fetch_first_and_every_nth_value_for_column(conn, column_to_fetch, n):
207207
return ids
208208

209209

210-
def truncate_tables(db, tables):
210+
def truncate_tables(db, tables, commit=True):
211211
logging.info("Deleting tables: " + ", ".join(table.__name__ for table in tables))
212212
for table in tables:
213213
db.session.query(table).delete()
214-
db.session.commit()
214+
if commit:
215+
db.session.commit()
215216

216217

217218
def delete_all_rows_from_table(conn, table):

0 commit comments

Comments
 (0)