From ced3bffd693956c5f20ddcc9106251b7257604a6 Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:04:04 +0000 Subject: [PATCH] pass task data from the db if data cannot be found on the expected task on the interstitial page (#1440) Co-authored-by: jasquat --- .../routes/tasks_controller.py | 15 ++++++++++++--- .../services/jinja_service.py | 6 ++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index 5e2d4877a..2a7d2731f 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -486,8 +486,8 @@ def task_with_instruction(process_instance_id: int) -> Response: return make_response(jsonify({"task": task}), 200) -def _render_instructions(spiff_task: SpiffTask) -> str: - return JinjaService.render_instructions_for_end_user(spiff_task) +def _render_instructions(spiff_task: SpiffTask, task_data: dict | None = None) -> str: + return JinjaService.render_instructions_for_end_user(spiff_task, task_data=task_data) def _interstitial_stream( @@ -588,9 +588,18 @@ def _interstitial_stream( spiff_task = processor.next_task() if spiff_task is not None and spiff_task.id not in reported_ids: + task_data = spiff_task.data + if task_data is None or task_data == {}: + json_data = ( + JsonDataModel.query.join(TaskModel, TaskModel.json_data_hash == JsonDataModel.hash) + .filter(TaskModel.guid == str(spiff_task.id)) + .first() + ) + if json_data is not None: + task_data = json_data.data task = ProcessInstanceService.spiff_task_to_api_task(processor, spiff_task) try: - instructions = _render_instructions(spiff_task) + instructions = _render_instructions(spiff_task, task_data=task_data) except Exception as e: api_error = ApiError( error_code="engine_steps_error", diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/jinja_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/jinja_service.py index 2026ad9b1..8007f724d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/jinja_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/jinja_service.py @@ -38,7 +38,9 @@ class JinjaHelpers: class JinjaService: @classmethod - def render_instructions_for_end_user(cls, task: TaskModel | SpiffTask | None = None, extensions: dict | None = None) -> str: + def render_instructions_for_end_user( + cls, task: TaskModel | SpiffTask | None = None, extensions: dict | None = None, task_data: dict | None = None + ) -> str: """Assure any instructions for end user are processed for jinja syntax.""" if extensions is None: if isinstance(task, TaskModel): @@ -48,7 +50,7 @@ class JinjaService: if extensions and "instructionsForEndUser" in extensions: if extensions["instructionsForEndUser"]: try: - return cls.render_jinja_template(extensions["instructionsForEndUser"], task) + return cls.render_jinja_template(extensions["instructionsForEndUser"], task, task_data=task_data) except TaskModelError as wfe: wfe.add_note("Failed to render instructions for end user.") raise ApiError.from_workflow_exception("instructions_error", str(wfe), exp=wfe) from wfe