From 674380001fb9ad3d0634a66eca15daf8e1465971 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 13 Feb 2023 10:13:51 -0500 Subject: [PATCH 1/2] This should fix the len issue - though there may be better ways to fix this. This reverts commit d1e2d292111c9e81b0fc9177c8f7546a8a6e8462. --- .../routes/process_instances_controller.py | 1 + .../services/process_instance_processor.py | 23 ++++++++++--------- .../services/service_task_service.py | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py index 800c50c9..40a0147f 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -125,6 +125,7 @@ def process_instance_run( raise e except Exception as e: ErrorHandlingService().handle_error(processor, e) + # fixme: this is going to point someone to the wrong task - it's misinformation for errors in sub-processes task = processor.bpmn_process_instance.last_task raise ApiError.from_task( error_code="unknown_exception", diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index f30ebd4b..3090aa5c 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -208,20 +208,21 @@ class NonTaskDataBasedScriptEngineEnvironment(BasePythonScriptEngineEnvironment) self.state.update(self.globals) self.state.update(external_methods or {}) self.state.update(context) - exec(script, self.state) # noqa + try: + exec(script, self.state) # noqa + finally: + # since the task data is not directly mutated when the script executes, need to determine which keys + # have been deleted from the environment and remove them from task data if present. + context_keys_to_drop = context.keys() - self.state.keys() - # since the task data is not directly mutated when the script executes, need to determine which keys - # have been deleted from the environment and remove them from task data if present. - context_keys_to_drop = context.keys() - self.state.keys() + for key_to_drop in context_keys_to_drop: + context.pop(key_to_drop) - for key_to_drop in context_keys_to_drop: - context.pop(key_to_drop) + self.state = self._user_defined_state(external_methods) - self.state = self._user_defined_state(external_methods) - - # the task data needs to be updated with the current state so data references can be resolved properly. - # the state will be removed later once the task is completed. - context.update(self.state) + # the task data needs to be updated with the current state so data references can be resolved properly. + # the state will be removed later once the task is completed. + context.update(self.state) def _user_defined_state( self, external_methods: Optional[Dict[str, Any]] = None diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py index 98243611..2ff09af2 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py @@ -113,7 +113,7 @@ class ServiceTaskDelegate: message = ServiceTaskDelegate.get_message_for_status( proxied_response.status_code ) - error = f"Received an unexpected response from the service : {message}" + error = f"Received an unexpected response from service {name} : {message}" if "error" in parsed_response: error += parsed_response["error"] if json_parse_error: From 03f8b625995d7b8bd35f2280fcb4cde7967d4b25 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 13 Feb 2023 10:38:21 -0500 Subject: [PATCH 2/2] run_pyl --- .../spiffworkflow_backend/services/service_task_service.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py index 2ff09af2..8d4fd43b 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py @@ -113,7 +113,9 @@ class ServiceTaskDelegate: message = ServiceTaskDelegate.get_message_for_status( proxied_response.status_code ) - error = f"Received an unexpected response from service {name} : {message}" + error = ( + f"Received an unexpected response from service {name} : {message}" + ) if "error" in parsed_response: error += parsed_response["error"] if json_parse_error: