In scripts/load.py line 1448, Mission.objects.get_or_create() includes thumbnail_filename, notes_filename, grid_bounds, and directory as lookup fields alongside name:
mission, created = Mission.objects.get_or_create(
name=os.path.dirname(fp).replace(MBARI_DIR, ""),
grid_bounds=grid_bounds,
notes_filename=notes_filename,
thumbnail_filename=thumbnail_filename,
directory=os.path.dirname(fp),
)
Because all fields are part of the lookup key, if any field changes between bootstrap runs (e.g. thumbnail_filename is empty on the first run because locate hasn't indexed the file yet, then non-empty on a subsequent run), Django creates a second Mission with the same name rather than updating the existing one.
This causes cascading failures: the --spreadsheets phase calls Mission.objects.get(name=...) which crashes with MultipleObjectsReturned when duplicates exist.
Fix: Move all fields except name into a defaults={} dict, and use update_or_create so re-runs safely update rather than duplicate:
mission, created = Mission.objects.update_or_create(
name=os.path.dirname(fp).replace(MBARI_DIR, ""),
defaults={
"grid_bounds": grid_bounds,
"notes_filename": notes_filename,
"thumbnail_filename": thumbnail_filename,
"directory": os.path.dirname(fp),
}
)
In scripts/load.py line 1448, Mission.objects.get_or_create() includes thumbnail_filename, notes_filename, grid_bounds, and directory as lookup fields alongside name:
Because all fields are part of the lookup key, if any field changes between bootstrap runs (e.g. thumbnail_filename is empty on the first run because locate hasn't indexed the file yet, then non-empty on a subsequent run), Django creates a second Mission with the same name rather than updating the existing one.
This causes cascading failures: the --spreadsheets phase calls Mission.objects.get(name=...) which crashes with MultipleObjectsReturned when duplicates exist.
Fix: Move all fields except name into a defaults={} dict, and use update_or_create so re-runs safely update rather than duplicate: