Skip to content
Snippets Groups Projects
Commit 124ea0c4 authored by Megan Henning's avatar Megan Henning Committed by GitHub
Browse files

Merge pull request #942 from scitran/file-type-fix

Handle files with type of None
parents ca6b0a8e 4f55cf04
No related branches found
Tags 1.0.72
No related merge requests found
...@@ -67,10 +67,11 @@ def eval_match(match_type, match_param, file_, container): ...@@ -67,10 +67,11 @@ def eval_match(match_type, match_param, file_, container):
# Match the file's type # Match the file's type
if match_type == 'file.type': if match_type == 'file.type':
try: file_type = file_.get('type')
return file_['type'].lower() == match_param.lower() if file_type:
except KeyError: return file_type.lower() == match_param.lower()
_log_file_key_error(file_, container, 'has no type key') else:
_log_file_key_error(file_, container, 'has no type')
return False return False
# Match a shell glob for the file name # Match a shell glob for the file name
...@@ -91,7 +92,8 @@ def eval_match(match_type, match_param, file_, container): ...@@ -91,7 +92,8 @@ def eval_match(match_type, match_param, file_, container):
# Match the container having any file (including this one) with this type # Match the container having any file (including this one) with this type
elif match_type == 'container.has-type': elif match_type == 'container.has-type':
for c_file in container['files']: for c_file in container['files']:
if match_param.lower() == c_file.get('type').lower(): c_file_type = c_file.get('type')
if c_file_type and match_param.lower() == c_file_type.lower():
return True return True
return False return False
......
...@@ -376,6 +376,11 @@ def test_rules(randstr, data_builder, file_form, as_root, as_admin, with_user, a ...@@ -376,6 +376,11 @@ def test_rules(randstr, data_builder, file_form, as_root, as_admin, with_user, a
) )
assert r.ok assert r.ok
# Ensure file without type or measurements does not cause issues with rule evalution
# upload file that matches only part of rule
r = as_admin.post('/projects/' + project + '/files', files=file_form('test3.notreal'))
assert r.ok
# test that only one job was created via rule # test that only one job was created via rule
gear_jobs = [job for job in api_db.jobs.find({'gear_id': gear_2})] gear_jobs = [job for job in api_db.jobs.find({'gear_id': gear_2})]
assert len(gear_jobs) == 2 assert len(gear_jobs) == 2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment