From 3e650ff8637e11715401ae2c74c21d2e99f2e03c Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sun, 17 May 2026 22:45:22 +0200 Subject: [PATCH] fix(task-base): on_failure logging crashes on reserved LogRecord keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- app/modules/task_base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/modules/task_base.py b/app/modules/task_base.py index 7e5e12fe..c5af50d1 100644 --- a/app/modules/task_base.py +++ b/app/modules/task_base.py @@ -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), },