-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling FileNotFoundError in BIDSLayout Initialization when is_derivative=True and validate=False, also resolves #1050 #1049
Conversation
Description of the "is_derivative" parameter of BIDSLayout states that this parameter "can be enabled along with validate=False to index derivatives without dataset_description.json." However, the initialization method of BIDSLayout calls "validate_derivative_path(root)" on line 141, which eventually leads to a "FileNotFoundError" as the this function then tries to read a dataset_description.json file that does not exist. This commit fixes this issue by catching this FileNotFoundError and restores intended functionality.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1049 +/- ##
=======================================
Coverage 89.80% 89.80%
=======================================
Files 63 63
Lines 7178 7178
Branches 1374 1374
=======================================
Hits 6446 6446
Misses 532 532
Partials 200 200 ☔ View full report in Codecov by Sentry. |
bids/layout/index.py
Outdated
@@ -265,6 +265,7 @@ def _index_metadata(self): | |||
# ensure we are returning objects | |||
filters['return_type'] = 'object' | |||
|
|||
ext_key = 'extensions' if 'extensions' in filters else 'extension' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was correctly removed, but ext_key
failed to get changed to 'extension'
in the next 5 lines. Could you apply that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand correctly, would you like me to remove the line I added and change the next 5 lines to this instead:
if filters.get('extension'):
filters['extension'] = listify(filters['extension'])
# ensure json files are being indexed
if '.json' not in filters['extension']:
filters['extension'].append('.json')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, you got it. Thanks!
This pull request addresses an issue encountered when initializing a
BIDSLayout
with a derivatives directory that does not contain adataset_description.json
file. Previously, aFileNotFoundError
would be raised in such cases, even whenvalidate=False
was set.The proposed change allows for a
FileNotFoundError
to be caught and handled gracefully during the initialization of aBIDSLayout
. This allows for the indexing of derivatives without adataset_description.json
file, aligning with the description ofis_derivative
parameter that states this parameter "can be enabled along with validate=False to index derivatives without dataset_description.json."The specific change involves modifying the exception handling at line 142 in
layout.py
to catch bothBIDSValidationError
andFileNotFoundError
. This ensures that the initialization process can continue even if thedataset_description.json
file is missing.