summaryrefslogtreecommitdiff
path: root/src/mailman/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/app')
-rw-r--r--src/mailman/app/tests/test_workflow.py2
-rw-r--r--src/mailman/app/workflow.py22
2 files changed, 8 insertions, 16 deletions
diff --git a/src/mailman/app/tests/test_workflow.py b/src/mailman/app/tests/test_workflow.py
index e82001540..70e9a5035 100644
--- a/src/mailman/app/tests/test_workflow.py
+++ b/src/mailman/app/tests/test_workflow.py
@@ -153,7 +153,7 @@ class TestWorkflow(unittest.TestCase):
# Save the state of an old version of the workflow that would not have
# the cat attribute.
state_manager.save(
- self._workflow.token, 'first',
+ self._workflow.token, '["first"]',
json.dumps({'ant': 1, 'bee': 2}))
# Restore in the current version that needs the cat attribute.
new_workflow = MyWorkflow()
diff --git a/src/mailman/app/workflow.py b/src/mailman/app/workflow.py
index 92b78c184..e705668f8 100644
--- a/src/mailman/app/workflow.py
+++ b/src/mailman/app/workflow.py
@@ -56,7 +56,7 @@ class Workflow:
self._next.append(step)
def _pop(self):
- name = self._next.popleft()
+ name = self._next.pop()
step = getattr(self, '_step_{}'.format(name))
self._count += 1
if self.debug: # pragma: nocover
@@ -119,20 +119,12 @@ class Workflow:
assert self.token, 'Workflow token must be set'
state_manager = getUtility(IWorkflowStateManager)
data = {attr: getattr(self, attr) for attr in self.SAVE_ATTRIBUTES}
- # Note: only the next step is saved, not the whole stack. This is not
- # an issue in practice, since there's never more than a single step in
- # the queue anyway. If we want to support more than a single step in
- # the queue *and* want to support state saving/restoring, change this
- # method and the restore() method.
+ # Save the workflow stack.
if len(self._next) == 0:
- step = None
- elif len(self._next) == 1:
- step = self._next[0]
+ steps = '[]'
else:
- raise AssertionError(
- "Can't save a workflow state with more than one step "
- "in the queue")
- state_manager.save(self.token, step, json.dumps(data))
+ steps = json.dumps(list(self._next))
+ state_manager.save(self.token, steps, json.dumps(data))
def restore(self):
state_manager = getUtility(IWorkflowStateManager)
@@ -141,8 +133,8 @@ class Workflow:
# The token doesn't exist in the database.
raise LookupError(self.token)
self._next.clear()
- if state.step:
- self._next.append(state.step)
+ if state.steps:
+ self._next.extend(json.loads(state.steps))
data = json.loads(state.data)
for attr in self.SAVE_ATTRIBUTES:
try: