<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have verified that the issue exists against the <code class="notranslate">main</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> This has already been asked to the <a href="https://github.com/celery/celery/discussions">discussions forum</a> first.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="https://docs.celeryq.dev/en/main/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/main">commit log</a><br>
to find out if the bug was already fixed in the main branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have verified that the issue exists against the <code class="notranslate">main</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>: 5.2.7</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: 3.7.16</li>
<li><strong>Minimal Celery Version</strong>: 5.2.7</li>
<li><strong>Minimal Kombu Version</strong>: 5.2.4</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Django==2.2.28
celery==5.2.7
billiard==3.6.4
pytz==2022.7.1"><pre class="notranslate"><code class="notranslate">Django==2.2.28
celery==5.2.7
billiard==3.6.4
pytz==2022.7.1
</code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# dajngo-test-case
    def simple_test_test(self):
        mocked_smth = self.patch(
            'path.to.tasks.patched_counter',
            side_effect=[Exception, True]
        )
        with self.assertRaises(Retry):
            patching_method()
        self.assertEqual(mocked_smth.call_count, 2)

# tasks.py
@shared_task(bind=True)
def patching_method(self):
    try:
        patched_counter()
    except Exception as e:
        raise self.retry(exc=e) # Retry raises, but do not retries task as well

def patched_counter():
    pass"><pre class="notranslate"><span class="pl-c"># dajngo-test-case</span>
    <span class="pl-k">def</span> <span class="pl-en">simple_test_test</span>(<span class="pl-s1">self</span>):
        <span class="pl-s1">mocked_smth</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">patch</span>(
            <span class="pl-s">'path.to.tasks.patched_counter'</span>,
            <span class="pl-s1">side_effect</span><span class="pl-c1">=</span>[<span class="pl-v">Exception</span>, <span class="pl-c1">True</span>]
        )
        <span class="pl-k">with</span> <span class="pl-s1">self</span>.<span class="pl-en">assertRaises</span>(<span class="pl-v">Retry</span>):
            <span class="pl-en">patching_method</span>()
        <span class="pl-s1">self</span>.<span class="pl-en">assertEqual</span>(<span class="pl-s1">mocked_smth</span>.<span class="pl-s1">call_count</span>, <span class="pl-c1">2</span>)

<span class="pl-c"># tasks.py</span>
<span class="pl-en">@<span class="pl-en">shared_task</span>(<span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">patching_method</span>(<span class="pl-s1">self</span>):
    <span class="pl-k">try</span>:
        <span class="pl-en">patched_counter</span>()
    <span class="pl-k">except</span> <span class="pl-v">Exception</span> <span class="pl-k">as</span> <span class="pl-s1">e</span>:
        <span class="pl-k">raise</span> <span class="pl-s1">self</span>.<span class="pl-en">retry</span>(<span class="pl-s1">exc</span><span class="pl-c1">=</span><span class="pl-s1">e</span>) <span class="pl-c"># Retry raises, but do not retries task as well</span>

<span class="pl-k">def</span> <span class="pl-en">patched_counter</span>():
    <span class="pl-k">pass</span></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">I'm expecting, that after raising Retry inside Django tests it will retry task and set patched_counter to 2</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">So it is just running trough first side_effect, raises Retry, so assertRaises works, and going through test function without retry task.<br>
My suggest is this is in case of:<br>
a) Retry just cannot be faster, then test case (it is not blocking, so it is async maybe?)<br>
b) Retry just do not running (I'm not sure why?)</p>
<p dir="auto">It worked before update to 5.2.7 from 4.3.1, also updated billiard and pytz to required.</p>
<p dir="auto">Also here is the ENVs:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CELERY_WORKER_DISABLE_RATE_LIMITS = True
CELERY_SEND_TASK_ERROR_EMAILS = False
CELERY_TASK_ANNOTATIONS = {
    &quot;*&quot;: {
        &quot;on_failure&quot;: celery_on_failure # incapsulated logging
    }
}
CELERY_QUEUE_HA_POLICY = 'all'
BROKER_HOST = os.getenv('BROKER_HOST', 'localhost')
BROKER_PORT = os.getenv('BROKER_PORT', 5672)
BROKER_USER = os.getenv('BROKER_USER', 'guest')
BROKER_PASSWORD = os.getenv('BROKER_PASSWORD', 'guest')
BROKER_VHOST = os.getenv('BROKER_VHOST', '/')

CELERY_RESULT_BACKEND = 'rpc://{BROKER_USER}:{BROKER_PASSWORD}@{BROKER_HOST}:{BROKER_PORT}/{BROKER_VHOST}'.format(
    BROKER_USER=BROKER_USER,
    BROKER_PASSWORD=BROKER_PASSWORD,
    BROKER_HOST=BROKER_HOST,
    BROKER_PORT=BROKER_PORT,
    BROKER_VHOST=BROKER_VHOST,
)
CELERY_RESULT_PERSISTENT = True
CELERY_TASK_IGNORE_RESULT = True
"><pre class="notranslate"><span class="pl-v">CELERY_WORKER_DISABLE_RATE_LIMITS</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
<span class="pl-v">CELERY_SEND_TASK_ERROR_EMAILS</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
<span class="pl-v">CELERY_TASK_ANNOTATIONS</span> <span class="pl-c1">=</span> {
    <span class="pl-s">"*"</span>: {
        <span class="pl-s">"on_failure"</span>: <span class="pl-s1">celery_on_failure</span> <span class="pl-c"># incapsulated logging</span>
    }
}
<span class="pl-v">CELERY_QUEUE_HA_POLICY</span> <span class="pl-c1">=</span> <span class="pl-s">'all'</span>
<span class="pl-v">BROKER_HOST</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-en">getenv</span>(<span class="pl-s">'BROKER_HOST'</span>, <span class="pl-s">'localhost'</span>)
<span class="pl-v">BROKER_PORT</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-en">getenv</span>(<span class="pl-s">'BROKER_PORT'</span>, <span class="pl-c1">5672</span>)
<span class="pl-v">BROKER_USER</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-en">getenv</span>(<span class="pl-s">'BROKER_USER'</span>, <span class="pl-s">'guest'</span>)
<span class="pl-v">BROKER_PASSWORD</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-en">getenv</span>(<span class="pl-s">'BROKER_PASSWORD'</span>, <span class="pl-s">'guest'</span>)
<span class="pl-v">BROKER_VHOST</span> <span class="pl-c1">=</span> <span class="pl-s1">os</span>.<span class="pl-en">getenv</span>(<span class="pl-s">'BROKER_VHOST'</span>, <span class="pl-s">'/'</span>)

<span class="pl-v">CELERY_RESULT_BACKEND</span> <span class="pl-c1">=</span> <span class="pl-s">'rpc://{BROKER_USER}:{BROKER_PASSWORD}@{BROKER_HOST}:{BROKER_PORT}/{BROKER_VHOST}'</span>.<span class="pl-en">format</span>(
    <span class="pl-v">BROKER_USER</span><span class="pl-c1">=</span><span class="pl-v">BROKER_USER</span>,
    <span class="pl-v">BROKER_PASSWORD</span><span class="pl-c1">=</span><span class="pl-v">BROKER_PASSWORD</span>,
    <span class="pl-v">BROKER_HOST</span><span class="pl-c1">=</span><span class="pl-v">BROKER_HOST</span>,
    <span class="pl-v">BROKER_PORT</span><span class="pl-c1">=</span><span class="pl-v">BROKER_PORT</span>,
    <span class="pl-v">BROKER_VHOST</span><span class="pl-c1">=</span><span class="pl-v">BROKER_VHOST</span>,
)
<span class="pl-v">CELERY_RESULT_PERSISTENT</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
<span class="pl-v">CELERY_TASK_IGNORE_RESULT</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span></pre></div>
<p dir="auto">And especially for testing:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True"><pre class="notranslate"><span class="pl-v">CELERY_TASK_ALWAYS_EAGER</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
<span class="pl-v">CELERY_TASK_EAGER_PROPAGATES</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span></pre></div>
<p dir="auto">Tried to run with eager_mode to False, but it says that Retry does not raising.</p>
<p dir="auto">Here also the celery_app file:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from django.conf import settings

project_name = 'name' 
app = celery.Celery(project_name)
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">django</span>.<span class="pl-s1">conf</span> <span class="pl-k">import</span> <span class="pl-s1">settings</span>

<span class="pl-s1">project_name</span> <span class="pl-c1">=</span> <span class="pl-s">'name'</span> 
<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-s1">celery</span>.<span class="pl-v">Celery</span>(<span class="pl-s1">project_name</span>)
<span class="pl-s1">app</span>.<span class="pl-en">config_from_object</span>(<span class="pl-s">'django.conf:settings'</span>, <span class="pl-s1">namespace</span><span class="pl-c1">=</span><span class="pl-s">'CELERY'</span>)
<span class="pl-s1">app</span>.<span class="pl-en">autodiscover_tasks</span>(<span class="pl-k">lambda</span>: <span class="pl-s1">settings</span>.<span class="pl-v">INSTALLED_APPS</span>)</pre></div>
<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have verified that the issue exists against the <code class="notranslate">main</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> This has already been asked to the <a href="https://github.com/celery/celery/discussions">discussions forum</a> first.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have read the relevant section in the<br>
<a href="https://docs.celeryq.dev/en/main/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the <a href="https://github.com/celery/celery/commits/main">commit log</a><br>
to find out if the bug was already fixed in the main branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have verified that the issue exists against the <code class="notranslate">main</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>:</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Celery Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<h1 dir="auto">Actual Behavior</h1>