Skip to content
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

Merged
merged 5 commits into from
May 10, 2024

Conversation

alperkent
Copy link
Contributor

This pull request addresses an issue encountered when initializing a BIDSLayout with a derivatives directory that does not contain a dataset_description.json file. Previously, a FileNotFoundError would be raised in such cases, even when validate=False was set.

The proposed change allows for a FileNotFoundError to be caught and handled gracefully during the initialization of a BIDSLayout. This allows for the indexing of derivatives without a dataset_description.json file, aligning with the description of is_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 both BIDSValidationError and FileNotFoundError. This ensures that the initialization process can continue even if the dataset_description.json file is missing.

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.
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 89.80%. Comparing base (09448ad) to head (2320324).

Files Patch % Lines
bids/layout/index.py 0.00% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@@ -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'
Copy link
Collaborator

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?

Copy link
Contributor Author

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')

@alperkent alperkent changed the title Handling FileNotFoundError in BIDSLayout Initialization when is_derivative=True and validate=False Handling FileNotFoundError in BIDSLayout Initialization when is_derivative=True and validate=False, also resolves #1050 May 10, 2024
Copy link
Collaborator

@effigies effigies left a 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!

@effigies effigies merged commit 87eecc5 into bids-standard:master May 10, 2024
20 checks passed
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.

None yet

2 participants