Skip to content

Fix RoiMask rescan of existing fields with only_new_fields=False - #87

Open
DYYDMC wants to merge 1 commit into
mainfrom
fix/roimask-rescan-existing-fields
Open

DYYDMC wants to merge 1 commit into
mainfrom
fix/roimask-rescan-existing-fields

Conversation

@DYYDMC

@DYYDMC DYYDMC commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

RoiMask().rescan_filesystem(only_new_fields=False) crashed on any field that already has a RoiMask, so presentations added to existing fields later (for example a newly registered stimulus) could not get ROI masks. Cause: the existing main entry was fetched and re-inserted. In DataJoint 2 a fetched <filepath> is an ObjectRef, which fails insert validation before skip_duplicates applies.

 _add_field_roi_masks(field_key)
   if field has no RoiMask
     pick main mask from files
   else
     fetch main mask, roi_mask_file, roi_mask_source
+    roi_mask_file = relative_store_path(local_file_path(roi_mask_file))   # ObjectRef -> str
   build RoiMaskPresentation rows (auto_fill rows reuse main roi_mask_file)
-  insert1(main_key, skip_duplicates=True)
+  if field had no RoiMask
+    insert1(main_key, skip_duplicates=True)
   insert RoiMaskPresentation rows

Evidence

  • Before: real project schema, 11 new FlashesBGW presentations on 11 existing fields:

    RoiMask().rescan_filesystem(roi_mask_dir='ROIs', only_new_fields=False)
    -> roi_mask.py:755 self.insert1(main_key, skip_duplicates=True)
    TypeError: <filepath> expects a path string or Path, got ObjectRef
    

    After: same call adds the 11 RoiMaskPresentation rows (all as_field_mask='same'). The RoiMask count stays at 32, and Traces/Snippets populate for the new presentations.

  • New integration test _check_rescan_adds_presentations_to_existing_field (in test_tutorial_pipeline):

    rescan → delete one non-main RoiMaskPresentation → rescan(only_new_fields=False)
    assert row restored with same mask; main RoiMask unchanged
    

    It fails with the TypeError above without the fix. It runs in the MySQL integration workflow, which was not run locally (no MySQL test server). Unit tests pass locally (288 passed, 32 skipped).

Merge Danger

Door: two-way

Blast Radius: small

Only affects rescan_filesystem for fields that already have a RoiMask, which previously always raised. New fields go through the unchanged path.

🤖 Generated with Claude Code

When a field already has a RoiMask, _add_field_roi_masks fetched the
main entry and re-inserted it with skip_duplicates=True. In DataJoint 2
a fetched <filepath> is an ObjectRef, which fails insert validation
(TypeError: <filepath> expects a path string or Path, got ObjectRef),
so new presentations of existing fields (e.g. a newly added stimulus)
could not be added.

- Only insert the main entry for new fields
- Convert the fetched roi_mask_file back to a store-relative path, as it
  is also used for presentations filled via auto_fill_pres_keys
- Add an integration regression test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant