Skip to content

Commit

Permalink
serialize extensions when converting tasks to and from dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
essweine committed Jul 17, 2024
1 parent cd9c3eb commit c45ab5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 0 additions & 8 deletions SpiffWorkflow/bpmn/serializer/default/process_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,11 @@

class BpmnProcessSpecConverter(BpmnConverter):

def convert_task_spec_extensions(self, task_spec, dct):
# Extensions will be moved out of the base parser, but since we currently add them to some
# indeterminate set of tasks, we'll just check all the tasks for them here.
if hasattr(task_spec, 'extensions'):
dct.update({'extensions': task_spec.extensions})

def restore_task_spec_extensions(self, dct, task_spec):
if 'extensions' in dct:
task_spec.extensions = dct.pop('extensions')

def to_dict(self, spec):

dct = {
'name': spec.name,
'description': spec.description,
Expand All @@ -46,7 +39,6 @@ def to_dict(self, spec):
}
for name, task_spec in spec.task_specs.items():
task_dict = self.registry.convert(task_spec)
self.convert_task_spec_extensions(task_spec, task_dict)
dct['task_specs'][name] = task_dict

return dct
Expand Down
7 changes: 6 additions & 1 deletion SpiffWorkflow/bpmn/serializer/helpers/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_default_attributes(self, spec):
Returns:
dict: a dictionary of standard task spec attributes
"""
return {
dct = {
'name': spec.name,
'description': spec.description,
'manual': spec.manual,
Expand All @@ -150,6 +150,9 @@ def get_default_attributes(self, spec):
'data_output_associations': self.registry.convert(spec.data_output_associations),
'io_specification': self.registry.convert(spec.io_specification),
}
if hasattr(spec, 'extensions'):
dct['extensions'] = spec.extensions
return dct

def get_join_attributes(self, spec):
"""Extracts attributes for task specs that inherit from `Join`.
Expand Down Expand Up @@ -213,6 +216,8 @@ def task_spec_from_dict(self, dct):
bpmn_id = dct.pop('bpmn_id')

spec = self.target_class(wf_spec, name, **dct)
if 'extensions' in dct:
spec.extensions = dct['extensions']

if issubclass(self.target_class, BpmnSpecMixin) and bpmn_id != name:
# This is a hack for multiinstance tasks :( At least it is simple.
Expand Down

0 comments on commit c45ab5e

Please sign in to comment.