Issue 1:
Checklist

I have verified that the issue exists against the main branch of Celery.

This has already been asked to the discussions forum first.

I have read the relevant section in the

contribution guide

on reporting bugs.

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the main branch.

I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

I have included the output of celery -A proj report in the issue.

(if you are not able to do this, then at least specify the Celery

version affected).

I have verified that the issue exists against the main branch of Celery.

I have included the contents of pip freeze in the issue.

I have included all the versions of all the external dependencies required

to reproduce this bug.

Optional Debugging Information

I have tried reproducing the issue on more than one Python version

and/or implementation.

I have tried reproducing the issue on more than one message broker and/or

result backend.

I have tried reproducing the issue on more than one version of the message

broker and/or result backend.

I have tried reproducing the issue on more than one operating system.

I have tried reproducing the issue on more than one workers pool.

I have tried reproducing the issue with autoscaling, retries,

ETA/Countdown & rate limits disabled.

I have tried reproducing the issue after downgrading

and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

None

Possible Duplicates

None

Environment & Settings

Celery version: 5.2.7

celery report Output:

Steps to Reproduce

Required Dependencies

Minimal Python Version: 3.7.16

Minimal Celery Version: 5.2.7

Minimal Kombu Version: 5.2.4

Minimal Broker Version: N/A or Unknown

Minimal Result Backend Version: N/A or Unknown

Minimal OS and/or Kernel Version: N/A or Unknown

Minimal Broker Client Version: N/A or Unknown

Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

Django==2.2.28
celery==5.2.7
billiard==3.6.4
pytz==2022.7.1

Other Dependencies

N/A

Minimally Reproducible Test Case

# 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

Expected Behavior

I'm expecting, that after raising Retry inside Django tests it will retry task and set patched_counter to 2

Actual Behavior

So it is just running trough first side_effect, raises Retry, so assertRaises works, and going through test function without retry task.

My suggest is this is in case of:

a) Retry just cannot be faster, then test case (it is not blocking, so it is async maybe?)

b) Retry just do not running (I'm not sure why?)

It worked before update to 5.2.7 from 4.3.1, also updated billiard and pytz to required.

Also here is the ENVs:

CELERY_WORKER_DISABLE_RATE_LIMITS = True
CELERY_SEND_TASK_ERROR_EMAILS = False
CELERY_TASK_ANNOTATIONS = {
"*": {
"on_failure": 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

And especially for testing:

CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True

Tried to run with eager_mode to False, but it says that Retry does not raising.

Here also the celery_app file:

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)

Issue 2:
Checklist

I have verified that the issue exists against the main branch of Celery.

This has already been asked to the discussions forum first.

I have read the relevant section in the

contribution guide

on reporting bugs.

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the main branch.

I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

I have included the output of celery -A proj report in the issue.

(if you are not able to do this, then at least specify the Celery

version affected).

I have verified that the issue exists against the main branch of Celery.

I have included the contents of pip freeze in the issue.

I have included all the versions of all the external dependencies required

to reproduce this bug.

Optional Debugging Information

I have tried reproducing the issue on more than one Python version

and/or implementation.

I have tried reproducing the issue on more than one message broker and/or

result backend.

I have tried reproducing the issue on more than one version of the message

broker and/or result backend.

I have tried reproducing the issue on more than one operating system.

I have tried reproducing the issue on more than one workers pool.

I have tried reproducing the issue with autoscaling, retries,

ETA/Countdown & rate limits disabled.

I have tried reproducing the issue after downgrading

and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

None

Possible Duplicates

None

Environment & Settings

Celery version:

celery report Output:

Steps to Reproduce

Required Dependencies

Minimal Python Version: N/A or Unknown

Minimal Celery Version: N/A or Unknown

Minimal Kombu Version: N/A or Unknown

Minimal Broker Version: N/A or Unknown

Minimal Result Backend Version: N/A or Unknown

Minimal OS and/or Kernel Version: N/A or Unknown

Minimal Broker Client Version: N/A or Unknown

Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

Other Dependencies

N/A

Minimally Reproducible Test Case

Expected Behavior

Actual Behavior