Skip to content

Commit 13d00bf

Browse files
committed
FIX: Do not allow filters to overwrite participant / session
1 parent 2a10a59 commit 13d00bf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

niworkflows/utils/bids.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ def collect_data(
226226
>>> bids_root['t1w'] # doctest: +ELLIPSIS
227227
['.../ds051/sub-01/anat/sub-01_run-01_T1w.nii.gz']
228228
229+
>>> bids_root, _ = collect_data(
230+
... str(datadir / 'ds114'),
231+
... '01',
232+
... bids_validate=False,
233+
... session_id='retest',
234+
... bids_filters={'bold': {'session': 'madeup'}}) # doctest: +ELLIPSIS
235+
Traceback (most recent call last):
236+
...
237+
ValueError: Conflicting entities for "session" found: madeup - retest
238+
229239
"""
230240
if isinstance(bids_dir, BIDSLayout):
231241
layout = bids_dir
@@ -242,6 +252,22 @@ def collect_data(
242252
queries = queries or DEFAULT_BIDS_QUERIES
243253
bids_filters = bids_filters or {}
244254
for acq, entities in bids_filters.items():
255+
# BIDS filters will not be able to override subject / session entities
256+
if (
257+
'subject' in entities
258+
and participant_label
259+
and participant_label != entities['subject']
260+
):
261+
raise ValueError(
262+
'Conflicting entities for "participant" found: '
263+
f'{entities["subject"]} - {participant_label}'
264+
)
265+
if 'session' in entities and session_id and session_id != entities['session']:
266+
raise ValueError(
267+
'Conflicting entities for "session" found: '
268+
f'{entities["session"]} - {session_id}'
269+
)
270+
245271
queries[acq].update(entities)
246272
for entity in list(layout_get_kwargs.keys()):
247273
if entity in entities:

0 commit comments

Comments
 (0)