From 86b248faf387cc520fb7773e405308b9a2023ec1 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 3 Feb 2023 17:01:03 -0500 Subject: [PATCH] Fix that dreadful unknown "KeyError" exception that was cropping up. Adding a bit of detail to the spiffworkflow exceptions when a duplicate process model is found. Disable the submit button on tasks after you click submit (avoid the double click and give users a better experience) --- src/spiffworkflow_backend/exceptions/api_error.py | 4 ++++ src/spiffworkflow_backend/routes/tasks_controller.py | 12 +++++++----- .../services/process_model_service.py | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/spiffworkflow_backend/exceptions/api_error.py b/src/spiffworkflow_backend/exceptions/api_error.py index 9fe08bec..bb6d84f4 100644 --- a/src/spiffworkflow_backend/exceptions/api_error.py +++ b/src/spiffworkflow_backend/exceptions/api_error.py @@ -242,6 +242,10 @@ def handle_exception(exception: Exception) -> flask.wrappers.Response: api_exception = None if isinstance(exception, ApiError): api_exception = exception + elif isinstance(exception, SpiffWorkflowException): + api_exception = ApiError.from_workflow_exception( + "unexpected_workflow_exception", "Unexpected Workflow Error", exception + ) else: api_exception = ApiError( error_code=error_code, diff --git a/src/spiffworkflow_backend/routes/tasks_controller.py b/src/spiffworkflow_backend/routes/tasks_controller.py index 2879c120..6f272287 100644 --- a/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/src/spiffworkflow_backend/routes/tasks_controller.py @@ -275,7 +275,7 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response ) from exception if task.data: - _update_form_schema_with_task_data_as_needed(form_dict, task) + _update_form_schema_with_task_data_as_needed(form_dict, task, spiff_task) if form_contents: task.form_schema = form_dict @@ -588,7 +588,9 @@ def _get_spiff_task_from_process_instance( # originally from: https://bitcoden.com/answers/python-nested-dictionary-update-value-where-any-nested-key-matches -def _update_form_schema_with_task_data_as_needed(in_dict: dict, task: Task) -> None: +def _update_form_schema_with_task_data_as_needed( + in_dict: dict, task: Task, spiff_task: SpiffTask +) -> None: """Update_nested.""" if task.data is None: return None @@ -615,7 +617,7 @@ def _update_form_schema_with_task_data_as_needed(in_dict: dict, task: Task) -> N f" '{task_data_var}' but it doesn't exist in" " the Task Data." ), - task=task, + task=spiff_task, ) raise ( ApiError.from_workflow_exception( @@ -648,11 +650,11 @@ def _update_form_schema_with_task_data_as_needed(in_dict: dict, task: Task) -> N in_dict[k] = options_for_react_json_schema_form elif isinstance(value, dict): - _update_form_schema_with_task_data_as_needed(value, task) + _update_form_schema_with_task_data_as_needed(value, task, spiff_task) elif isinstance(value, list): for o in value: if isinstance(o, dict): - _update_form_schema_with_task_data_as_needed(o, task) + _update_form_schema_with_task_data_as_needed(o, task, spiff_task) def _get_potential_owner_usernames(assigned_user: AliasedClass) -> Any: diff --git a/src/spiffworkflow_backend/services/process_model_service.py b/src/spiffworkflow_backend/services/process_model_service.py index d0c43fb2..d00ed011 100644 --- a/src/spiffworkflow_backend/services/process_model_service.py +++ b/src/spiffworkflow_backend/services/process_model_service.py @@ -499,7 +499,10 @@ class ProcessModelService(FileSystemService): if name is None: raise ApiError( error_code="missing_name_of_process_model", - message="Missing name of process model. It should be given", + message=( + "Missing name of process model. Path not found:" + f" {json_file_path}" + ), ) process_model_info = ProcessModelInfo(