fix a minor error with json serialization, by uysing SpiffWorkflows 'DefaultRegistry' the same converter used in spiffworkflow for our api call serialization. And using SpiffWorkflow's updated calculate_correlations so we create the same corelations in the same way as the core library when synching things up.

This commit is contained in:
Dan Funk 2025-02-26 10:32:07 -05:00
parent 8376c4655e
commit 519f994f2f
2 changed files with 13 additions and 3 deletions

View File

@ -158,7 +158,12 @@ class MessageService:
message_instance_receive.failure_cause = str(exception)
db.session.add(message_instance_receive)
if processor_receive is not None:
processor_receive.save()
# We may not be able to save here, this can raise a new exception.
try:
processor_receive.save()
except Exception:
db.session.commit()
raise exception
else:
db.session.commit()
if isinstance(exception, SpiffWorkflowException):
@ -234,10 +239,13 @@ class MessageService:
name=message_instance_send.name,
correlation_properties=correlation_properties,
)
correlations = bpmn_message.calculate_correlations(
CustomBpmnScriptEngine(), bpmn_message.correlation_properties, message_instance_send.payload
)
bpmn_event = BpmnEvent(
event_definition=bpmn_message,
payload=message_instance_send.payload,
correlations=message_instance_send.correlation_keys,
correlations=correlations,
)
processor_receive_to_use = processor_receive
save_engine_steps = False

View File

@ -10,6 +10,7 @@ from flask import g
from security import safe_requests # type: ignore
from SpiffWorkflow.bpmn import BpmnEvent # type: ignore
from SpiffWorkflow.bpmn.exceptions import WorkflowTaskException # type: ignore
from SpiffWorkflow.bpmn.serializer.helpers.registry import DefaultRegistry # type: ignore
from SpiffWorkflow.spiff.specs.defaults import ServiceTask # type: ignore
from SpiffWorkflow.spiff.specs.event_definitions import ErrorEventDefinition # type: ignore
from SpiffWorkflow.spiff.specs.event_definitions import EscalationEventDefinition
@ -59,7 +60,7 @@ class CustomServiceTask(ServiceTask): # type: ignore
wte.add_note(str(e))
raise wte from e
parsed_result = json.loads(result)
spiff_task.data[self._result_variable(spiff_task)] = parsed_result
spiff_task.data[self.result_variable] = parsed_result
return True
@ -193,6 +194,7 @@ class ServiceTaskDelegate:
with sentry_sdk.start_span(op="call-connector", description=call_url):
params = {k: cls.value_with_secrets_replaced(v["value"]) for k, v in bpmn_params.items()}
params["spiff__task_data"] = task_data
params = DefaultRegistry().convert(params) # Avoid serlization errors by using the same coverter as the core lib.
response_text = ""
status_code = 0