Skip to content

feat(task): allow acks_on_failure to be a callable deciding per exception - #10898

Open
abdullahmujahidali wants to merge 2 commits into
celery:mainfrom
abdullahmujahidali:feat/callable-acks-on-failure-9342
Open

abdullahmujahidali wants to merge 2 commits into
celery:mainfrom
abdullahmujahidali:feat/callable-acks-on-failure-9342

Conversation

@abdullahmujahidali

@abdullahmujahidali abdullahmujahidali commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #9342

With acks_late, the decision to ack a failed task is made in the worker main process, but Task.on_failure() runs in the pool child. So changing acks_on_failure from on_failure, as described in the issue, has no effect.

This lets acks_on_failure also be a method that takes the exception and returns whether to acknowledge. It's called in the main process when the ack decision is made. Plain True/False work as before, and timeouts still use acks_on_timeout.

Example from the issue, keeping meses on a transient error areexhausted:

class DLQTask(Task):
    acks_late = True
    autoretry_for = (ConnectionError,)

    def acks_on_failure(self, exc):
        return not isinstance(e

One open question: if the method itlogged and the message isacknowledged (the current default). Would rejecting be better?

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.15%. Comparing base (6fcdbf9) to head (1742462).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10898   +/-   ##
=======================================
  Coverage   91.15%   91.15%           
=======================================
  Files         153      153           
  Lines       21777    21786    +9     
  Branches     2701     2702    +1     
=======================================
+ Hits        19850    19859    +9     
  Misses       1619     1619           
  Partials      308      308           
Flag Coverage Δ
unittests 91.13% <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 added this to the 5.8.0 milestone Oct 19, 2026
@abdullahmujahidali
abdullahmujahidali marked this pull request as ready for review October 23, 2026 17:57

@auvipy auvipy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is slated for next feature release. so priority for reviewing this is now right now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable per-task acks_on_failure_or_timeout

2 participants