Repository navigation
Do not recurse when getting the metadata of an NWB file in a BIDS dataset - #1958
Draft
CodyCBakerPhD wants to merge 1 commit into
Draft
CodyCBakerPhD wants to merge 1 commit into
CodyCBakerPhD wants to merge 1 commit into
Conversation
…aset For an NWB file in a BIDS dataset, get_metadata() took the BIDS metadata from NWBBIDSAsset.get_metadata(), which also extracts the NWB metadata by calling nwb2asset() and thus get_metadata() again, and so on until RecursionError: ~100 levels, each running the BIDS validator. The result was still correct, as each level falls back on errors, but it took about a minute per file (and timed out CI on Windows). Take only the BIDS metadata, with BIDSAsset.get_metadata(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qn5WBSiQgoZoL4fytF6nEr
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1958 +/- ##
==========================================
+ Coverage 90.77% 90.80% +0.03%
==========================================
Files 92 92
Lines 14130 14142 +12
==========================================
+ Hits 12826 12842 +16
+ Misses 1304 1300 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
For an NWB file in a BIDS dataset,
dandi.metadata.nwb.get_metadata()took the BIDS part of the metadata fromdf.get_metadata().dfis anNWBBIDSAsset, and itsget_metadata()also extracts the NWB metadata, viaNWBAsset.get_metadata()→nwb2asset()→get_metadata(). That calls back into the same BIDS branch, so the cycle repeats untilRecursionError.The result was still correct, because
NWBAsset.get_metadata()falls back to default metadata on errors at each level. But the BIDS validator ran at every one of roughly 100 levels. Onieeg_epilepsyNWBfrom bids-examples, oneget_metadata()call made 98 nestednwb2asset()calls and took about 60 s. That is what madetest_bids_nwb_metadata_integrationtime out on Windows CI.Fix
Take only the BIDS metadata, via
bids.BIDSAsset.get_metadata(df, ...), which was the intent of that branch. The NWB metadata is extracted by the rest ofget_metadata()itself.Measured on the same file:
nwb2asset()callssubject_id/sex01/U01/UTests
test_bids_nwb_metadata_no_recursion, which spies onnwb2asset(). It fails on the current master (68 calls) and passes with the fix.dandi/tests/test_metadata.py,dandi/tests/test_files.py,dandi/filesanddandi/validate/tests/test_core.pypass locally: 198 passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01Qn5WBSiQgoZoL4fytF6nEr
Generated by Claude Code