From 6014f2940daf371a3f9a3cfdacf59bd5ef3a9760 Mon Sep 17 00:00:00 2001 From: Kevin Burnett <18027+burnettk@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:00:30 -0700 Subject: [PATCH] fix serialization issue with custom service task, w/ essweine (#605) Co-authored-by: burnettk --- .../bin/execute_tasks_for_process_instance.py | 2 +- .../services/process_instance_processor.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spiffworkflow-backend/bin/execute_tasks_for_process_instance.py b/spiffworkflow-backend/bin/execute_tasks_for_process_instance.py index 54567698..9964eeb2 100644 --- a/spiffworkflow-backend/bin/execute_tasks_for_process_instance.py +++ b/spiffworkflow-backend/bin/execute_tasks_for_process_instance.py @@ -7,7 +7,7 @@ def main() -> None: app = create_app() with app.app_context(): execution_strategy_name = app.config["SPIFFWORKFLOW_BACKEND_ENGINE_STEP_DEFAULT_STRATEGY_BACKGROUND"] - process_instance = ProcessInstanceModel.query.filter_by(id=29).first() + process_instance = ProcessInstanceModel.query.filter_by(id=2).first() ProcessInstanceService.run_process_instance_with_processor( process_instance, execution_strategy_name=execution_strategy_name ) 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 bd946b83..95b768c8 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -41,6 +41,7 @@ from SpiffWorkflow.serializer.exceptions import MissingSpecError # type: ignore from SpiffWorkflow.spiff.parser.process import SpiffBpmnParser # type: ignore from SpiffWorkflow.spiff.serializer.config import SPIFF_CONFIG # type: ignore from SpiffWorkflow.spiff.serializer.task_spec import ServiceTaskConverter # type: ignore +from SpiffWorkflow.spiff.specs.defaults import ServiceTask # type: ignore from SpiffWorkflow.task import Task as SpiffTask # type: ignore from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore from SpiffWorkflow.util.task import TaskIterator # type: ignore @@ -99,12 +100,21 @@ from spiffworkflow_backend.services.workflow_execution_service import execution_ from spiffworkflow_backend.specs.start_event import StartEvent from sqlalchemy import and_ + +# this custom converter is just so we use 'ServiceTask' as the typename in the serialization +# rather than 'CustomServiceTask' +class CustomServiceTaskConverter(ServiceTaskConverter): # type: ignore + def __init__(self, target_class, registry, typename: str = "ServiceTask"): # type: ignore + super().__init__(target_class, registry, typename) + + SPIFF_CONFIG[StartEvent] = EventConverter SPIFF_CONFIG[JSONDataStore] = JSONDataStoreConverter SPIFF_CONFIG[JSONFileDataStore] = JSONFileDataStoreConverter SPIFF_CONFIG[KKVDataStore] = KKVDataStoreConverter SPIFF_CONFIG[TypeaheadDataStore] = TypeaheadDataStoreConverter -SPIFF_CONFIG[CustomServiceTask] = ServiceTaskConverter +SPIFF_CONFIG[CustomServiceTask] = CustomServiceTaskConverter +del SPIFF_CONFIG[ServiceTask] # Sorry about all this crap. I wanted to move this thing to another file, but # importing a bunch of types causes circular imports.