diff --git a/wagtail/admin/tests/test_workflows.py b/wagtail/admin/tests/test_workflows.py index 33b7e13768..b3413db9bb 100644 --- a/wagtail/admin/tests/test_workflows.py +++ b/wagtail/admin/tests/test_workflows.py @@ -923,6 +923,8 @@ class TestDisableViews(TestCase, WagtailTestUtils): self.assertEqual(states.filter(status=WorkflowState.STATUS_IN_PROGRESS).count(), 0) self.assertEqual(states.filter(status=WorkflowState.STATUS_CANCELLED).count(), 1) + self.assertEqual(TaskState.objects.filter(workflow_state__workflow=self.workflow, status=TaskState.STATUS_IN_PROGRESS).count(), 0) + def test_disable_task(self): """Test that deactivating a task sets it to inactive and cancels in progress states""" self.login(self.submitter) diff --git a/wagtail/core/models.py b/wagtail/core/models.py index f74cb6e915..a1b8438d60 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -2837,6 +2837,9 @@ class WorkflowState(models.Model): def update(self, user=None, next_task=None): """Checks the status of the current task, and progresses (or ends) the workflow if appropriate. If the workflow progresses, next_task will be used to start a specific task next if provided.""" + if self.status != self.STATUS_IN_PROGRESS: + # Updating a completed or cancelled workflow should have no effect + return try: current_status = self.current_task_state.status except AttributeError: @@ -2880,6 +2883,9 @@ class WorkflowState(models.Model): raise PermissionDenied self.status = self.STATUS_CANCELLED self.save() + for state in self.task_states.filter(status=TaskState.STATUS_IN_PROGRESS): + # Cancel all in progress task states + state.specific.cancel(user=user) workflow_cancelled.send(sender=self.__class__, instance=self, user=user) @transaction.atomic