diff --git a/django_celery_results/backends/database.py b/django_celery_results/backends/database.py index 7353bc6f..a218b2b7 100644 --- a/django_celery_results/backends/database.py +++ b/django_celery_results/backends/database.py @@ -265,7 +265,6 @@ def on_chord_part_return(self, request, state, result, **kwargs): else: # Last task in the chord header has finished call_callback = True - chord_counter.delete() if call_callback: deps = chord_counter.group_result(app=self.app) @@ -276,6 +275,10 @@ def on_chord_part_return(self, request, state, result, **kwargs): callback=callback, group_result=deps ) + chord_counter.delete() + else: + logger.warning("Chord %s executed more " + "tasks than expected", gid) def trigger_callback(app, callback, group_result): diff --git a/t/unit/backends/test_database.py b/t/unit/backends/test_database.py index ef1e8e26..e881440e 100644 --- a/t/unit/backends/test_database.py +++ b/t/unit/backends/test_database.py @@ -862,8 +862,8 @@ def test_on_chord_part_return_failure(self): request.id = tid2 self.b.mark_as_failure(tid2, ValueError(), request=request) - with pytest.raises(ChordCounter.DoesNotExist): - ChordCounter.objects.get(group_id=gid) + chord_counter.refresh_from_db() + assert chord_counter.count == 1 request.chord.delay.assert_not_called()