Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions api/jobs/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ def lower(x):

# Match the file's type
if match_type == 'file.type':
try:
return file_['type'].lower() == match_param.lower()
except KeyError:
_log_file_key_error(file_, container, 'has no type key')
file_type = file_.get('type')
if file_type:
return file_type.lower() == match_param.lower()
else:
_log_file_key_error(file_, container, 'has no type')
return False

# Match a shell glob for the file name
Expand All @@ -91,7 +92,8 @@ def lower(x):
# Match the container having any file (including this one) with this type
elif match_type == 'container.has-type':
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 False
Expand Down
5 changes: 5 additions & 0 deletions test/integration_tests/python/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ def test_rules(randstr, data_builder, file_form, as_root, as_admin, with_user, a
)
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
gear_jobs = [job for job in api_db.jobs.find({'gear_id': gear_2})]
assert len(gear_jobs) == 2
Expand Down