Repository navigation
Closed
Description
Checklist
- version 4.0.2 of celery
- im just copying the examples from the docs from here: http://docs.celeryproject.org/en/latest/userguide/canvas.html#error-handling
Steps to reproduce
file1.py
from celery import chord, group
from app.graph.tasks import on_chord_error, add, xsum
c = (group(add.s(i, i) for i in range(1)) | xsum.s().on_error(on_chord_error.s())).delay()
tasks.py
@shared_task
def add(x, y):
raise Exception("bob")
@shared_task
def xsum(numbers):
return sum(numbers)
@shared_task
def on_chord_error(request, exc, traceback):
print('calling this random error method!!!!')
print('Task {0!r} raised error: {1!r}'.format(request.id, exc))
Expected behavior
That the on_chord_error callback would be invoked and would print out "calling this random error method"
Actual behavior
Whether I define an on_error callback or not (e.g. c = (group(add.s(i, i) for i in range(1)) | xsum.s().on_error(on_chord_error.s())).delay() versus c = (group(add.s(i, i) for i in range(1)) | xsum.s()).delay() , i get this same output:
output
django | [2016-12-20 23:32:14,688: INFO/MainProcess] Received task: app.graph.tasks.add[c5eeb13a-21f6-4f15-ac22-eab0784d2806]
django | [2016-12-20 23:32:16,068: ERROR/PoolWorker-2] Task app.graph.tasks.add[c5eeb13a-21f6-4f15-ac22-eab0784d2806] raised unexpected: Exception('bob',)
django | Traceback (most recent call last):
django | File "/usr/local/lib/python3.5/site-packages/celery/app/trace.py", line 367, in trace_task
django | R = retval = fun(*args, **kwargs)
django | File "/usr/local/lib/python3.5/site-packages/celery/app/trace.py", line 622, in __protected_call__
django | return self.run(*args, **kwargs)
django | File "/usr/src/app/graph/tasks.py", line 44, in add
django | raise Exception("bob")
django | Exception: bob
It never calls the on_error handler.
normal circumstances work:
If I rewrite add from
@shared_task
def add(x, y):
raise Exception("bob")
to this:
@shared_task
def add(x, y):
return x + y
then everything works. So I believe one of three things is going on:
- the documentation regarding group / chord error handling is incorrect
- chord / group error handling does not work
- i'm misinterpreting how error handling is supposed to work in celery (i have scoured the internet for good examples, but i cannot find any good examples of people propagating errors from a group of subprocesses. I would think this would be a very common thing!)
What is the celery equivalent of something like this from Node.js land?
var async = require('async');
async.auto({
thing1: function(){},
thing2: function(){}
}, function(err, results) {
if (err) {
// do stuff!
}
// do normal stuff post batch of stuff
})
Reacted by Erick Almeida, Eric Palakovich Carr, scobb, MrHen, John Rattz, Linni, austinbutler, Luke Vincent, Jono Brogan, 0xTiger and 2 more
Activity
NickStefan commentedon Dec 21, 2016
I am able to trigger the on_chord_error callback if I change add
from this
to this
However, it doesnt call the on error callback with the correct arguments, AND it still calls the xsum method.
I still think this issue either points to missing documentation or a bug
NickStefan commentedon Dec 21, 2016
I found the issue! This is definitely related #3574
NickStefan commentedon Dec 21, 2016
#3597 also
NickStefan commentedon Dec 21, 2016
the code from here #3323 seems to be the cause
NickStefan commentedon Dec 21, 2016
callback and callback error doesn't work with one task (callback never called):
callback and callback error does work with two tasks
br1anjtuck commentedon Jan 30, 2017
Any new progress on this issue? I ran into the same issue that @NickStefan experienced, and unless I am misinterpreting the documentation, it does seem like the callback should be called for proper chord error handling
NickStefan commentedon Jan 30, 2017
@br1anjtuck we just made some helpers that always add a blank task when using chords (to ensure there are always at least 2 tasks)
br1anjtuck commentedon Jan 31, 2017
Ok. So with the added helper task above, are you getting the user defined callback (your "do_on_error" task) to occur or are you getting a simple Chod Callback? (i.e. something like below):
I am only getting the above chord callback error and I am not getting my defined callback error "on_chord_error" when I define the SAME tasks that you have from your first cell of this post, and run a group of to tasks chained to the "xsum" callback (exactly like you did in the second part of the cell before I first posted) :
I am supposed to getting this "on_chord_error" callback error, right? Or should it only be the Chord callback?
NickStefan commentedon Jan 31, 2017
yes, i am getting the user defined callback when I always make sure to add a task (to ensure theres always at least two)
br1anjtuck commentedon Jan 31, 2017
Hmm..interesting. I don't know why, but with the same code, I am only getting the Chord callback and am not getting the user-defined callback. The only time I get the user-defined callback error is when I raise an exception in the "xsum" task rather than in the "add" task.
br1anjtuck commentedon Jan 31, 2017
Are you doing the below instead of raising an exception in your task?:
NickStefan commentedon Feb 1, 2017
Just doing regular exceptions. It was definitely tricky to get working, but yes an exception in add task is triggering the error callback
tlong-dev commentedon May 12, 2017
Yeah, I'm experiencing this as well. Seems to also be reported in #3317
rholloway commentedon May 30, 2017
@br1anjtuck did you ever figure out a solution to your problem? I seem to have the same situation as you with 4.0.2. My custom callback is called if the exception occurs in the chord callback (xsum), but if it occurs in individual task (add) it's never called.
I've tried sticking on_error onto each task in the header, onto the chord callback, onto the entire chord, everywhere. No luck.
chrisbrantley commentedon Jun 20, 2017
I'm having the same problem. The
on_erroris simply never called. It doesn't seem to matter how many tasks I have in the group. Very frustrating.63 remaining items
Miraliu commentedon Oct 5, 2023
celery==5.3.1
def on_chord_error(request_id, custom) no longer works for us...the callback is not invoked.
def on_chord_error(request, exc, traceback, custom) works.