Naming of BIDS '*events.tsv' files seems to disrupt fMRIprep 1.5.0rc1

Dear all,

I have been experimenting with using fMRIprep 1.5.0rc1. My BIDS-formatted data folder also contains task events files, such as ‘./sub-01/func/sub-01_task-Emotion_run-1_events.tsv’.

Strangely, when these files had a ‘run’ key in their filename, then fMRIprep 1.5.0rc1 (but not 1.4.1) exited with an error right after BIDS validation. But when I deleted the ‘run’ key (changing the file name to ‘sub-01_task-Emotion_x-1_events.tsv’), fMRIprep seemed to continue running fine.

I copied the error at the end of this message. I hope it is useful! Please let me know if you need any other information. My current workaround is simply to delete ‘*events.tsv’ files from a data set that I am running fMRIprep on. fMRIprep 1.5.0rc1 still seems very helpful though, as I seemed to have memory usage issues with 1.4.1 when I tried running it on a cluster.

Many thanks,

Research Assistant for cognitive fMRI projects at the University of Edinburgh

## Console output 
STARTING 67f6c8b8-9bfb-3a13-bc70-f14fa156a1ed

executing: fmriprep
Making sure the input data is BIDS compliant (warnings can be ignored in most cases).
1: [WARN] The recommended file /README is missing. See Section 03 (Modality agnostic files) of the BIDS specification. (code: 101 - README_FILE_MISSING)

Please visit for existing conversations about this issue.

        Summary:                  Available Tasks:        Available Modalities:
        14 Files, 919.43MB        Emotion                 T1w
        1 - Subject                                       T2w
        1 - Session                                       bold

        If you have any questions, please post on

Process Process-2:
Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.7/multiprocessing/", line 297, in _bootstrap
  File "/usr/local/miniconda/lib/python3.7/multiprocessing/", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/cli/", line 524, in build_workflow
    layout = BIDSLayout(str(bids_dir), validate=False)
  File "/usr/local/miniconda/lib/python3.7/site-packages/bids/layout/", line 212, in __init__
  File "/usr/local/miniconda/lib/python3.7/site-packages/bids/layout/", line 338, in index_metadata
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 1027, in commit
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 494, in commit
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 473, in _prepare_impl
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 2459, in flush
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 2597, in _flush
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/util/", line 68, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/util/", line 153, in reraise
    raise value
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 2557, in _flush
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 422, in execute
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 589, in execute
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 213, in save_obj
    ) in _organize_states_for_save(base_mapper, states, uowtransaction):
  File "/usr/local/miniconda/lib/python3.7/site-packages/sqlalchemy/orm/", line 408, in _organize_states_for_save
    % (state_str(state), instance_key, state_str(existing))
sqlalchemy.orm.exc.FlushError: New instance <Tag at 0x2b66784f7ba8> with identity key (<class 'bids.layout.models.Tag'>, ('/inp/sub-02/func/sub-02_task-Emotion_run-1_events.tsv', 'run'), None) conflicts with persistent instance <Tag at 0x2b66784c6630>

Hi @andres.tamm, it looks like a pybids issue - please follow up here

1 Like

I’ll reply on the pybids repo as well, but my initial guess is that you have another event file that’s conflicting with this one for some reason. Do you by chance have another *run-1_events.tsv file in a parent directory? Or multiple events.tsv in the current one?

1 Like

Thank you both for your quick reply! I do not have an additional events file, but I do have a .json file (*run-1_events.json) that describes custom columns in the *events.tsv file. If I remove the .json file, I no longer get the error message.

I wonder if that .json file was named correctly according to the BIDS standard? It was called ‘sub-01_task-Emotion_run-1_events.json’. When I submitted my data set to BIDS validator, I did not receive errors referring to my events files.

Let me know if there is anything else I can do to help clarify the error!

My data set folder had just one subject folder (‘sub-01’) and it contained the following files and folders:




Thank you again

Thanks Andres—I think this is a bug in PyBIDS. As far as I can see, what you’re doing is fine, and including a .json sidecar for events.tsv file is actually the recommended behavior.

Hi Tal, thanks, my .json file contained a description for a variable ‘run’ (see below). If I remove that block of text from the .json file, I no longer get the error that I had.

	"trial_type": {
		"LongName": "Trial type",
		"Description": "Primary categorisation of each trial",
		"Levels": {
			"cue_control": "Indicates cues in control block",
			"cue_emotion": "Indicates cues in emotion block",
			"cue_motivation": "Indicates cues in motivation block",
			"target_control": "Indicates targets in control block",
			"target_emotion": "Indicates targets in emotion block",
			"target_motivation": "Indicates targets in motvation block"
	"response_type": {
		"LongName": "Response type",
		"Description": "Participant's response to each target",
		"Levels": {
			"correct": "Indicates that response to target was correct",
			"incorrect": "Indicates that response to target was icorrect",
			"missing": "Indicates that response to target was missing"
	"response_time": {
		"LongName": "Response time",
		"Description": "Response time to targets measured in seconds",
		"Units": "seconds"
	"run": {
		"LongName": "Run",
		"Description": "Indicates the scanning run"
	"phase": {
		"LongName": "Task phase",
		"Description": "Indicates whether an event was a cue or a target",
		"Levels": {
			"cue": "Indicates cues",
			"target": "Indicates targets"
	"block": {
		"LongName": "Task block",
		"Description": "Indicates which task block the event belonged to",
		"Levels": {
			"control": "Indicates that event was in the control block",
			"emotion": "Indicates that event was in the emotion block",
			"motivation": "Indicates that event was in the motivation block"