pass task data from the db if data cannot be found on the expected task on the interstitial page (#1440)
Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
5e0c32474e
commit
ced3bffd69
|
@ -486,8 +486,8 @@ def task_with_instruction(process_instance_id: int) -> Response:
|
||||||
return make_response(jsonify({"task": task}), 200)
|
return make_response(jsonify({"task": task}), 200)
|
||||||
|
|
||||||
|
|
||||||
def _render_instructions(spiff_task: SpiffTask) -> str:
|
def _render_instructions(spiff_task: SpiffTask, task_data: dict | None = None) -> str:
|
||||||
return JinjaService.render_instructions_for_end_user(spiff_task)
|
return JinjaService.render_instructions_for_end_user(spiff_task, task_data=task_data)
|
||||||
|
|
||||||
|
|
||||||
def _interstitial_stream(
|
def _interstitial_stream(
|
||||||
|
@ -588,9 +588,18 @@ def _interstitial_stream(
|
||||||
|
|
||||||
spiff_task = processor.next_task()
|
spiff_task = processor.next_task()
|
||||||
if spiff_task is not None and spiff_task.id not in reported_ids:
|
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)
|
task = ProcessInstanceService.spiff_task_to_api_task(processor, spiff_task)
|
||||||
try:
|
try:
|
||||||
instructions = _render_instructions(spiff_task)
|
instructions = _render_instructions(spiff_task, task_data=task_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
api_error = ApiError(
|
api_error = ApiError(
|
||||||
error_code="engine_steps_error",
|
error_code="engine_steps_error",
|
||||||
|
|
|
@ -38,7 +38,9 @@ class JinjaHelpers:
|
||||||
|
|
||||||
class JinjaService:
|
class JinjaService:
|
||||||
@classmethod
|
@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."""
|
"""Assure any instructions for end user are processed for jinja syntax."""
|
||||||
if extensions is None:
|
if extensions is None:
|
||||||
if isinstance(task, TaskModel):
|
if isinstance(task, TaskModel):
|
||||||
|
@ -48,7 +50,7 @@ class JinjaService:
|
||||||
if extensions and "instructionsForEndUser" in extensions:
|
if extensions and "instructionsForEndUser" in extensions:
|
||||||
if extensions["instructionsForEndUser"]:
|
if extensions["instructionsForEndUser"]:
|
||||||
try:
|
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:
|
except TaskModelError as wfe:
|
||||||
wfe.add_note("Failed to render instructions for end user.")
|
wfe.add_note("Failed to render instructions for end user.")
|
||||||
raise ApiError.from_workflow_exception("instructions_error", str(wfe), exp=wfe) from wfe
|
raise ApiError.from_workflow_exception("instructions_error", str(wfe), exp=wfe) from wfe
|
||||||
|
|
Loading…
Reference in New Issue