@@ -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
@@ -239,9 +249,18 @@ def collect_data(
239249 'session' : session_id or Query .OPTIONAL ,
240250 }
241251
252+ reserved_entities = [('subject' , participant_label ), ('session' , session_id )]
253+
242254 queries = queries or DEFAULT_BIDS_QUERIES
243255 bids_filters = bids_filters or {}
244256 for acq , entities in bids_filters .items ():
257+ # BIDS filters will not be able to override subject / session entities
258+ for entity , param in reserved_entities :
259+ if entity in entities and param != entities [entity ]:
260+ raise ValueError (
261+ f'Conflicting entities for "{ entity } " found: { entities [entity ]} // { param } '
262+ )
263+
245264 queries [acq ].update (entities )
246265 for entity in list (layout_get_kwargs .keys ()):
247266 if entity in entities :
0 commit comments