Skip to content

Store failures raised as BaseException subclasses with the JSON serializer - #10672

Merged
auvipy merged 2 commits into
celery:mainfrom
GangEunzzang:fix/store-base-exception-failures
Sep 19, 2026
Merged

auvipy merged 2 commits into
celery:mainfrom
GangEunzzang:fix/store-base-exception-failures

Conversation

@GangEunzzang

Copy link
Copy Markdown
Contributor

Backend.encode_result() only runs prepare_exception() when the result is an Exception, so a task that fails with a bare BaseException or asyncio.CancelledError reaches the JSON encoder as the raw object and mark_as_failure() dies with EncodeError: Object of type BaseException is not JSON serializable. No result is written and the caller waits for its own timeout. Pickle is unaffected since it serializes the object as is.

This came up while looking at Billiard 4.3.0 in #10659: the worker loop now reports any BaseException a task raises instead of turning it into WorkerLostError. SystemExit and KeyboardInterrupt are handled in #10667; this covers the rest.

Checking BaseException instead is enough, exception_to_python() already accepts them on the way back. With a prefork worker against Redis, both cases now come back as the raised exception in well under a second where they used to time out.

…lizer

encode_result() only ran prepare_exception() for Exception instances, so
a task failing with a bare BaseException or asyncio.CancelledError reached
the JSON encoder as the raw object and mark_as_failure() died with
EncodeError. No result was ever written and callers waited for their own
timeout. Pickle was unaffected because it can serialize the object as is.

Prepare any BaseException the same way; exception_to_python() already
accepts them on the way back.
@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.14%. Comparing base (3ecf43b) to head (94967fe).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10672   +/-   ##
=======================================
  Coverage   89.14%   89.14%           
=======================================
  Files         153      153           
  Lines       20284    20284           
  Branches     2403     2403           
=======================================
  Hits        18082    18082           
  Misses       1897     1897           
  Partials      305      305           
Flag Coverage Δ
unittests 89.12% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy auvipy added this to the 5.7.0 milestone Sep 19, 2026
@auvipy
auvipy self-requested a review September 19, 2026 06:59
Comment thread t/unit/backends/test_base.py Resolved
@auvipy
auvipy merged commit 05e0ea4 into celery:main Sep 19, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants