fix(task-base): on_failure logging crashes on reserved LogRecord keys
Some checks failed
CI / ruff (push) Successful in 18s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / pytest (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled

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:
2026-05-17 22:45:22 +02:00
parent e680fda8bd
commit 3e650ff863

View File

@@ -113,8 +113,11 @@ class ModuleTask(Task):
extra={ extra={
"task_name": self.name, "task_name": self.name,
"task_id": task_id, "task_id": task_id,
"args": args, # NOT "args"/"kwargs" — both clash with reserved LogRecord
"kwargs": kwargs, # 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), "exception": str(exc),
"traceback": str(einfo), "traceback": str(einfo),
}, },