From b42b843f7df8c9e7ebac8b2c85d37c70488ba3a6 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 8 Feb 2021 15:10:53 -0500 Subject: [PATCH] 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. --- crc/services/workflow_service.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 74d070c0..139882c6 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -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)