Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure triggering of callback in chord #397

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django_celery_results/backends/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -276,6 +275,10 @@ def on_chord_part_return(self, request, state, result, **kwargs):
callback=callback,
group_result=deps
)
chord_counter.delete()
s-jakob marked this conversation as resolved.
Show resolved Hide resolved
else:
logger.warning("Chord %s executed more "
"tasks than expected", gid)


def trigger_callback(app, callback, group_result):
Expand Down
4 changes: 2 additions & 2 deletions t/unit/backends/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +865 to +866
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct, we have a header of 2, 1 is done, the other fails.
If a task in the header fails the chord is done and the callback is not called.

If this is the case, a ChordCounter object will remain in the db for every failed chord.


request.chord.delay.assert_not_called()

Expand Down
Loading