Dcm2bids crashes when the configuration file is set up with a list as a criteria but the tag is not defined in the JSON sidecar. I'm assuming that this is unintended behaviour and it should not match the criteria rather than crash the program.
Terminal output
```
lib/python3.10/site-packages/dcm2bids/dcm2bids_gen.py:116: in run
parser.build_graph()
lib/python3.10/site-packages/dcm2bids/sidecar.py:274: in build_graph
if criteria and self.isLink(sidecar.data, criteria):
lib/python3.10/site-packages/dcm2bids/sidecar.py:400: in isLink
result.append(compare(name, pattern))
lib/python3.10/site-packages/dcm2bids/sidecar.py:294: in compare
return bool(re.match(pattern, name))
lib/python3.10/re.py:190: in match
return _compile(pattern, flags).match(string)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pattern = ['.*', '.*', 'M', '.*'], flags = 0
def _compile(pattern, flags):
# internal: compile pattern
if isinstance(flags, RegexFlag):
flags = flags.value
try:
> return _cache[type(pattern), pattern, flags]
E TypeError: unhashable type: 'list'
lib/python3.10/re.py:293: TypeError
```
I believe the problem comes from here where the default value is set to a string if the tag does not exist but is later compared to a list which creates the crash. The default value should probably be an empty list for these tags.
Summary
Dcm2bids crashes when the configuration file is set up with a list as a criteria but the tag is not defined in the JSON sidecar. I'm assuming that this is unintended behaviour and it should not match the criteria rather than crash the program.
Terminal output
To reproduce:
Example config file:
Example JSON sidecar (CRASH)
Example JSON sidecar (NO CRASH)
Suggestion
I believe the problem comes from here where the default value is set to a string if the tag does not exist but is later compared to a list which creates the crash. The default value should probably be an empty list for these tags.
Linked files
I uploaded my test files for easier replication crash.json pass.json dcm2bids_test.json
Related
Related to https://github.com/shimming-toolbox/shimming-toolbox/issues/557