Skip to content

Commit fc5f651

Browse files
fix(er): proactively remove exception fields [backport 3.14] (#14663)
Backport ceded88 from #14649 to 3.14. ## Description Exception Replay introduces an unexpected interaction with Celery when tasks raise custom exceptions with mandatory arguments. It seems that holding on to exception fields, such as __cause__, for longer than necessary causes Celery to produce bad pickled responses that are not handled by the framework. We therefore proactively clear up our tracking of the exception fields that we want to capture to prevent Celery tasks from crashing the application. Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent 6a6beed commit fc5f651

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ddtrace/debugging/_signal/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,11 @@ def capture_value(
359359
elif len(fields) > maxfields:
360360
data["notCapturedReason"] = "fieldCount"
361361

362+
if _isinstance(value, BaseException):
363+
# DEV: Celery doesn't like that we store references to these objects so we
364+
# delete them as soon as we're done with them.
365+
for attr in ("args", "__cause__", "__context__", "__suppress_context__"):
366+
if attr in fields:
367+
del fields[attr]
368+
362369
return data
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
exception replay: prevent Celery from crashing when a task raises a custom
5+
exception with mandatory arguments.

0 commit comments

Comments
 (0)