summaryrefslogtreecommitdiff
path: root/src/mailman/app/subscriptions.py
diff options
context:
space:
mode:
authorAurélien Bompard2015-03-27 12:53:59 +0100
committerAurélien Bompard2015-03-27 12:53:59 +0100
commit2e4367b6aaba7b16a371cc98036ce2cbdeb35fbf (patch)
tree68d127c3c712e426f3ad506e2b9844f1b0f00698 /src/mailman/app/subscriptions.py
parent7f5d0e4d2b1d4043247543bb9c067d96e8280c2d (diff)
downloadmailman-2e4367b6aaba7b16a371cc98036ce2cbdeb35fbf.tar.gz
mailman-2e4367b6aaba7b16a371cc98036ce2cbdeb35fbf.tar.zst
mailman-2e4367b6aaba7b16a371cc98036ce2cbdeb35fbf.zip
Workflow: allow saving and restoring with an empty queue
Diffstat (limited to 'src/mailman/app/subscriptions.py')
-rw-r--r--src/mailman/app/subscriptions.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py
index 507f8bf28..375fe159d 100644
--- a/src/mailman/app/subscriptions.py
+++ b/src/mailman/app/subscriptions.py
@@ -93,19 +93,30 @@ class Workflow:
# Note: only the next step is saved, not the whole stack. Not an issue
# 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
- # restore_state().
+ # to support state saving/restoring, change this method and the
+ # restore_state() method.
+ if len(self._next) == 0:
+ step = None
+ elif len(self._next) == 1:
+ step = self._next[0]
+ else:
+ raise AssertionError(
+ "Can't save a workflow state with more than one step "
+ "in the queue")
state_manager.save(
self.__class__.__name__,
self._save_key,
- self._next[0],
+ step,
json.dumps(data))
def restore_state(self):
state_manager = getUtility(IWorkflowStateManager)
state = state_manager.restore(self.__class__.__name__, self._save_key)
if state is not None:
- self._next[0] = state.step
+ if not state.step:
+ self._next.clear()
+ else:
+ self._next[0] = state.step
if state.data is not None:
for attr, value in json.loads(state.data).items():
setattr(self, attr, value)