Issue 1:
When calling self.replace() with a signature reconstructed from a serialized dictionary (e.g. after having been passed through a backend), if that signature is (or contains) a group which itself contains a chord, celery explodes after attempting to treat deeply nested dictionaries as signature objects. See below for a minimal repro I got together today.

My gut feel is that instantiating a signature from a dictionary may not be recursing down through the structure far enough and it leaves some of the encapsulated tasks as dicts. I've also noticed that groups containing a group also break in the same way, but I think that's because there's an internal promotion to a chord happening somewhere.

Checklist

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

This has already been asked to the discussion group 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 master 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 master 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

#4015

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:

amqp==5.0.1
billiard==3.6.3.0
# Editable install with no version control (celery==5.0.0rc3)
-e /home/maybe/tmp/capp/venv/lib/python3.8/site-packages
click==7.1.2
click-didyoumean==0.0.3
click-repl==0.1.6
future==0.18.2
kombu==5.0.2
prompt-toolkit==3.0.7
pytz==2020.1
redis==3.5.3
six==1.15.0
vine==5.0.0
wcwidth==0.2.5

Other Dependencies

N/A

Minimally Reproducible Test Case

import celery

app = celery.Celery("app", backend="redis://")

@app.task
def foo(*_):
return 42

@app.task(bind=True)
def replace_with(self, sig):
assert isinstance(sig, dict)
sig = celery.Signature.from_dict(sig)
raise self.replace(sig)

if __name__ == "__main__":
sig = celery.group(
celery.group(foo.s()),
)
res = sig.delay()
print(res.get())

sig.freeze()
res = replace_with.delay(sig)
print(res.get())

Expected Behavior

It shouldn't explode. Presumably tasks within the group/chord should be signatures rather than dicts.

Actual Behavior

Stack trace in the worker output:

[2020-09-08 12:44:05,453: DEBUG/MainProcess] Task accepted: app.replace_with[dcea02fd-23a3-404a-9fdd-b213eb51c0d1] pid:453431
[2020-09-08 12:44:05,457: ERROR/ForkPoolWorker-8] Task app.replace_with[dcea02fd-23a3-404a-9fdd-b213eb51c0d1] raised unexpected: AttributeError("'dict' object has no attribute '_app'")
Traceback (most recent call last):
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/kombu/utils/objects.py", line 41, in __get__
return obj.__dict__[self.__name__]
KeyError: 'app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/celery/app/trace.py", line 409, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/celery/app/trace.py", line 701, in __protected_call__
return self.run(*args, **kwargs)
File "/home/maybe/tmp/capp/app.py", line 13, in replace_with
raise self.replace(sig)
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/celery/app/task.py", line 894, in replace
sig.freeze(self.request.id)
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/celery/canvas.py", line 1302, in freeze
self.tasks = group(self.tasks, app=self.app)
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/kombu/utils/objects.py", line 43, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/celery/canvas.py", line 1456, in app
return self._get_app(self.body)
File "/home/maybe/tmp/capp/venv/lib64/python3.8/site-packages/celery/canvas.py", line 1466, in _get_app
app = tasks[0]._app
AttributeError: 'dict' object has no attribute '_app'

Issue 2:
Checklist

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

This has already been asked to the discussion group 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 master 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 master 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

5.0.5 (singularity):

celery report Output:

software -> celery:5.0.5 (singularity) kombu:5.0.2 py:3.8.5
billiard:3.6.4.0 py-amqp:5.0.6
platform -> system:Linux arch:64bit, ELF
kernel version:5.8.0-48-generic imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:pyamqp results:redis://localhost/

broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'redis://localhost/'
deprecated_settings: None

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:

aiohttp==3.7.4.post0
aiohttp-cors==0.7.0
aioredis==1.3.1
amqp==5.0.6
anykeystore==0.2
apex==0.9.10.dev0
argh==0.26.2
argon2-cffi==20.1.0
astroid==2.4.2
async-generator==1.10
async-timeout==3.0.1
attrs==20.2.0
axial-positional-embedding==0.2.1
backcall==0.2.0
billiard==3.6.4.0
bleach==3.2.1
blessings==1.7
cachetools==4.2.1
celery==5.0.5
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
click==7.1.2
click-default-group==1.2.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
cloudpickle==1.6.0
colorama==0.4.4
colorful==0.5.4
contrastive-learner==0.1.0
cryptacular==1.5.5
cycler==0.10.0
dask==2021.4.0
db-to-sqlite==1.3
decorator==4.4.2
defusedxml==0.6.0
dlib==19.21.0
dnspython==1.16.0
entrypoints==0.3
eventlet==0.30.2
face-recognition==1.3.0
face-recognition-models==0.3.0
filelock==3.0.12
fire==0.3.1
Flask==1.1.2
Flask-Resize==2.0.4
fsspec==0.9.0
future==0.18.2
gevent==21.1.2
google-api-core==1.26.3
google-auth==1.29.0
google-images-download==2.8.0
googleapis-common-protos==1.53.0
gpustat==0.6.0
greenlet==1.0.0
grpcio==1.37.0
hiredis==2.0.0
hupper==1.10.2
idna==2.10
imageio==2.9.0
imutils==0.5.3
ipdb==0.13.4
ipykernel==5.3.4
ipython==7.18.1
ipython-genutils==0.2.0
ipywidgets==7.5.1
isort==5.6.4
itsdangerous==1.1.0
jedi==0.17.2
Jinja2==2.11.2
json5==0.9.5
jsonschema==3.2.0
jupyter-client==6.1.7
jupyter-core==4.6.3
jupyterlab==2.2.8
jupyterlab-pygments==0.1.2
jupyterlab-server==1.2.0
kiwisolver==1.2.0
kombu==5.0.2
kornia==0.4.1
lazy-object-proxy==1.4.3
linear-attention-transformer==0.14.1
linformer==0.2.0
local-attention==1.0.2
locket==0.2.1
lxml==4.6.2
MarkupSafe==1.1.1
matplotlib==3.3.2
mccabe==0.6.1
mistune==0.8.4
modin==0.9.1
msgpack==1.0.2
multidict==5.1.0
nbclient==0.5.0
nbconvert==6.0.7
nbformat==5.0.7
nest-asyncio==1.4.1
networkx==2.5
notebook==6.1.4
numpy==1.19.2
nvidia-ml-py3==7.352.0
oauthlib==3.1.0
opencensus==0.7.12
opencensus-context==0.1.2
opencv-python==4.4.0.46
packaging==20.4
pandas==1.1.3
pandocfilters==1.4.2
parso==0.7.1
partd==1.2.0
PasteDeploy==2.1.1
pbkdf2==1.3
pexpect==4.8.0
pickleshare==0.7.5
pika==1.2.0
pilkit==2.0
Pillow==7.2.0
plaster==1.0
plaster-pastedeploy==0.7
product-key-memory==0.1.10
prometheus-client==0.8.0
prompt-toolkit==3.0.8
protobuf==3.15.8
psutil==5.8.0
psycopg2==2.8.6
ptyprocess==0.6.0
py==1.9.0
py-spy==0.3.5
pyarrow==1.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
Pygments==2.7.1
pylint==2.6.0
pyparsing==2.4.7
pyramid==1.10.4
pyramid-mailer==0.15.1
pyrsistent==0.17.3
python-dateutil==2.8.1
python3-openid==3.2.0
pytorch-fid==0.1.1
pytz==2020.1
PyWavelets==1.1.1
pywikibot==5.6.0
PyYAML==5.4.1
pyzmq==19.0.2
ray==1.1.0
redis==3.5.3
repoze.sendmail==4.4.1
requests==2.24.0
requests-oauthlib==1.3.0
retry==0.9.2
rsa==4.7.2
scikit-image==0.18.1
scipy==1.5.3
selenium==3.141.0
Send2Trash==1.5.0
six==1.15.0
SQLAlchemy==1.3.20
sqlite-fts4==1.0.1
sqlite-utils==3.6
swifter==1.0.7
tabulate==0.8.9
termcolor==1.1.0
terminado==0.9.1
testpath==0.4.4
tifffile==2021.3.5
toml==0.10.1
toolz==0.11.1
torch==1.6.0
torchvision==0.7.0
tornado==6.0.4
tqdm==4.50.2
traitlets==5.0.4
transaction==3.0.0
translationstring==1.4
typing-extensions==3.7.4.3
urllib3==1.25.10
vector-quantize-pytorch==0.1.0
velruse==1.1.1
venusian==3.0.0
vine==5.0.0
wcwidth==0.2.5
webencodings==0.5.1
WebOb==1.8.6
Werkzeug==1.0.1
widgetsnbextension==3.5.1
wrapt==1.12.1
WTForms==2.3.3
wtforms-recaptcha==0.3.2
yarl==1.6.3
zope.deprecation==4.4.0
zope.event==4.5.0
zope.interface==5.1.2
zope.sqlalchemy==1.3

Other Dependencies

N/A

Minimally Reproducible Test Case

from celery import Celery
from celery.execute import send_task

#random_name = Celery('tasks', backend='redis://localhost', broker='pyamqp://')
r1 = send_task('tasks.add',(1,1))
print(r1.get())

Expected Behavior

2 printed to the screen without uncommenting the line #random_name

(it makes no sense for this line to have any effect on the program)

Actual Behavior

"No result backend" Exception, unless the only commented out line is uncommented.

Accompanying file:

tasks.py

from celery import Celery
app = Celery('tasks', backend='redis://localhost', broker='pyamqp://')

@app.task
def add(x, y):
return x + y

``