Skip to content

Mark rejected tasks as failed when not requeued - #10369

Merged
auvipy merged 3 commits into
celery:mainfrom
hmnfalahi:fix-reject-mark-failure
Jun 27, 2026
Merged

auvipy merged 3 commits into
celery:mainfrom
hmnfalahi:fix-reject-mark-failure

Conversation

@hmnfalahi

Copy link
Copy Markdown
Contributor

Description

Fixes #4222.

When a task raises Reject(requeue=False), the message is rejected and will not be executed again. Previously the result backend was not updated, which could leave the task in PENDING or STARTED.

This change records a terminal failure result for non-requeued rejects and emits the task_failure signal. Requeued rejects keep the existing behavior.

Added unit coverage for both non-requeued and requeued Reject paths.

@codecov

codecov Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.35%. Comparing base (41b8838) to head (6441c26).
⚠️ Report is 221 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10369   +/-   ##
=======================================
  Coverage   88.35%   88.35%           
=======================================
  Files         153      153           
  Lines       19770    19775    +5     
  Branches     2292     2294    +2     
=======================================
+ Hits        17467    17472    +5     
  Misses       2004     2004           
  Partials      299      299           
Flag Coverage Δ
unittests 88.32% <100.00%> (+<0.01%) ⬆️

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 self-requested a review June 21, 2026 08:20
@hmnfalahi
hmnfalahi marked this pull request as draft June 21, 2026 18:50
@hmnfalahi
hmnfalahi force-pushed the fix-reject-mark-failure branch from ccd47af to 37f70de Compare June 21, 2026 21:17
@hmnfalahi
hmnfalahi marked this pull request as ready for review June 21, 2026 21:19
@auvipy auvipy added this to the 5.7.0 milestone Jun 22, 2026
@auvipy
auvipy requested a review from Copilot June 24, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Celery issue #4222 by ensuring tasks that raise Reject(requeue=False) are recorded as a terminal failure (instead of being left in PENDING/STARTED), and by documenting and testing the updated behavior.

Changes:

  • Update Request.on_failure() to store a FAILURE result, emit task_failure, and send a task-failed event for Reject(requeue=False).
  • Add unit tests covering both non-requeued and requeued Reject paths (including the already-acked case).
  • Document the new semantics of Reject(requeue=False) vs Reject(requeue=True) in the user guide.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
celery/worker/request.py Records a terminal failure + emits failure signal/event when Reject(requeue=False) is raised.
t/unit/worker/test_request.py Adds regression tests for Reject handling (non-requeue and requeue paths).
docs/userguide/tasks.rst Documents how Celery treats Reject with and without requeue.

Comment thread celery/worker/request.py Resolved
Comment thread docs/userguide/tasks.rst Resolved
@hmnfalahi
hmnfalahi force-pushed the fix-reject-mark-failure branch 2 times, most recently from d9c7bad to 6b7711a Compare June 25, 2026 19:35
@hmnfalahi
hmnfalahi force-pushed the fix-reject-mark-failure branch from 6b7711a to 44cdc99 Compare June 25, 2026 21:46
Comment thread celery/worker/request.py Resolved
@auvipy
auvipy merged commit e2b276e into celery:main Jun 27, 2026
336 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.

Reject exception doesn't cause the task to fail

3 participants