Skip to content

Commit 124ea0c

Browse files
authored
Merge pull request #942 from scitran/file-type-fix
Handle files with type of None
2 parents ca6b0a8 + 4f55cf0 commit 124ea0c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

api/jobs/rules.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ def lower(x):
6767

6868
# Match the file's type
6969
if match_type == 'file.type':
70-
try:
71-
return file_['type'].lower() == match_param.lower()
72-
except KeyError:
73-
_log_file_key_error(file_, container, 'has no type key')
70+
file_type = file_.get('type')
71+
if file_type:
72+
return file_type.lower() == match_param.lower()
73+
else:
74+
_log_file_key_error(file_, container, 'has no type')
7475
return False
7576

7677
# Match a shell glob for the file name
@@ -91,7 +92,8 @@ def lower(x):
9192
# Match the container having any file (including this one) with this type
9293
elif match_type == 'container.has-type':
9394
for c_file in container['files']:
94-
if match_param.lower() == c_file.get('type').lower():
95+
c_file_type = c_file.get('type')
96+
if c_file_type and match_param.lower() == c_file_type.lower():
9597
return True
9698

9799
return False

test/integration_tests/python/test_rules.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ def test_rules(randstr, data_builder, file_form, as_root, as_admin, with_user, a
376376
)
377377
assert r.ok
378378

379+
# Ensure file without type or measurements does not cause issues with rule evalution
380+
# upload file that matches only part of rule
381+
r = as_admin.post('/projects/' + project + '/files', files=file_form('test3.notreal'))
382+
assert r.ok
383+
379384
# test that only one job was created via rule
380385
gear_jobs = [job for job in api_db.jobs.find({'gear_id': gear_2})]
381386
assert len(gear_jobs) == 2

0 commit comments

Comments
 (0)