It was possible for an enum field lookup to return an empty list. This meant there were no options for the list.

We now test for this and raise an error.
This commit is contained in:
mike cullerton 2021-02-08 15:10:53 -05:00
parent 329146237e
commit b42b843f7d
1 changed files with 5 additions and 1 deletions

View File

@ -316,7 +316,11 @@ class WorkflowService(object):
data = db.session.query(LookupDataModel).filter(
LookupDataModel.lookup_file_model == lookup_model).limit(10).all()
options = [{"value": d.value, "label": d.label, "data": d.data} for d in data]
return random.choice(options)
if len(options) > 0:
return random.choice(options)
else:
raise ApiError.from_task("invalid enum", "You specified an enumeration field (%s),"
" with no options" % field.id, task)
else:
raise ApiError.from_task("unknown_lookup_option", "The settings for this auto complete field "
"are incorrect: %s " % field.id, task)