Skip to content

Commit 95c5f18

Browse files
committed
avoid skip_duplicates to prevent database locks
1 parent 32b6950 commit 95c5f18

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/spyglass/utils/mixins/ingestion.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,15 @@ def insert_from_nwbfile(
253253

254254
# validate that new entries are consistent with existing entries
255255
if self._expected_duplicates:
256-
self.validate_duplicates(entries)
256+
entries_to_insert = self.validate_duplicates(entries)
257+
else:
258+
entries_to_insert = entries
257259

258260
# run insertions
259261
if not dry_run:
260-
self._run_nwbfile_insert(entries, nwb_file_name=nwb_file_name)
262+
self._run_nwbfile_insert(
263+
entries_to_insert, nwb_file_name=nwb_file_name
264+
)
261265

262266
return entries
263267

@@ -279,7 +283,7 @@ def expect_dupes(tbl):
279283
for table, table_entries in entries.items():
280284
table.insert(
281285
table_entries,
282-
skip_duplicates=expect_dupes(table),
286+
skip_duplicates=False,
283287
allow_direct_insert=True,
284288
)
285289
self._insert_logline(nwb_file_name, len(table_entries), table)
@@ -348,10 +352,23 @@ def validate_duplicates(self, entry_dict: Dict[dj.Table, List[dict]]):
348352
entry_dict : dict or Dict[dj.Table, List[dict]]
349353
The new entry or dict of table entries to validate against existing
350354
entries in the database.
355+
356+
Returns
357+
-------
358+
dict or Dict[dj.Table, List[dict]]
359+
The new entries to insert after validation. Avoids need to flag
360+
skip_duplicates
351361
"""
362+
entries_to_insert = dict()
352363
for table, table_entries in entry_dict.items():
353-
for entry in self._adjust_keys_for_entry(table_entries):
364+
entries_to_insert[table] = []
365+
for entry, table_entry in zip(
366+
self._adjust_keys_for_entry(table_entries), table_entries
367+
):
354368
self.validate1_duplicate(table, entry)
369+
if not (table & entry):
370+
entries_to_insert[table].append(table_entry)
371+
return entries_to_insert
355372

356373
def validate1_duplicate(self, tbl, new_key):
357374
"""If matching primary key, check for consistency in secondary keys.

0 commit comments

Comments
 (0)