Crash when a tag that usually contains a list is not in the JSON sidecar but present in the criteria of the config file
Closed this issue · 2 comments
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
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
To reproduce:
Example config file:
{
"search_method": "re",
"case_sensitive": false,
"descriptions": [
{
"datatype": "anat",
"suffix": "magnitude1",
"criteria": {
"ImageType": [".*", ".*", "M", ".*"]
}
}
]
}
Example JSON sidecar (CRASH)
{
"Modality": "MR"
}
Example JSON sidecar (NO CRASH)
{
"Modality": "MR"
"ImageType": []
}
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 shimming-toolbox/shimming-toolbox#557
Thank you @po09i, I'll take a look and fix it by the end of next week !
fixed in dev.