fix(task-base): on_failure logging crashes on reserved LogRecord keys
Some checks failed
Some checks failed
When a Celery task failed, on_failure passed extra={"args": ..., "kwargs": ...}
to logger.error. Python's logging.makeRecord rejects any extra key that
collides with a built-in LogRecord attribute, and "args" is one (used for
printf formatting). The KeyError raised inside the error handler then
cascaded through Celery's trace.handle_failure, masking the real task
exception entirely.
Rename the keys to task_args / task_kwargs.
Surfaced while debugging why the loyalty welcome email never got sent —
the underlying task was failing, but the on_failure handler crashed before
logging the real cause, leaving nothing in worker logs to investigate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -113,8 +113,11 @@ class ModuleTask(Task):
|
||||
extra={
|
||||
"task_name": self.name,
|
||||
"task_id": task_id,
|
||||
"args": args,
|
||||
"kwargs": kwargs,
|
||||
# NOT "args"/"kwargs" — both clash with reserved LogRecord
|
||||
# attribute names and cause logging.makeRecord to raise
|
||||
# KeyError, which then masks the real task failure.
|
||||
"task_args": args,
|
||||
"task_kwargs": kwargs,
|
||||
"exception": str(exc),
|
||||
"traceback": str(einfo),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user