Issue 1:
(56a6246 introduces a bug in 5.0.x, that is present in 5.0.6 but was not in 5.0.5. The line with return detach(... needs to be indented one step further, otherwise it's outside of the if ... block and argv is undefined. The issue is not present in the master branch.)

Checklist

I have verified that the issue exists against the master branch of Celery. It does not, it's in 5.0.6 only

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. It does not

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.0.6

celery report Output:

Steps to Reproduce

Run celery -A proj worker (note: no -D)

Required Dependencies

Minimal Python Version: N/A or Unknown

Minimal Celery Version: 5.0.6

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.6
asgiref==3.4.0
billiard==3.6.4.0
cairocffi==1.2.0
CairoSVG==2.5.2
canonicaljson==1.4.0
celery==5.0.6
certifi==2021.5.30
cffi==1.14.5
chardet==3.0.4
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.2.0
convertdate==2.3.2
cryptography==3.4.7
cssselect2==0.4.1
deepmerge==0.2.1
defusedxml==0.7.1
Deprecated==1.2.12
Django==3.1.12
django-admirarchy==1.2.1
django-bitfield==2.0.1
django-colorfield==0.4.1
django-cors-headers==3.5.0
django-countries==6.1.3
django-cte==1.1.5
django-enumfields==2.0.0
django-filter==2.4.0
django-health-check==3.16.4
django-json-widget==1.0.1
django-localflavor==3.0.1
django-macaddress==1.7.0
django-mass-edit==3.2.0
django-modern-rpc==0.12.1
django-otp==1.0.6
django-polymorphic==3.0.0
django-prometheus==2.1.0
django-recurrence==1.10.3
django-redis==4.12.1
djangorestframework==3.11.2
docopt==0.6.2
docutils==0.16
drf-enum-field==0.9.3
dynaconf==2.2.3
elementpath==2.2.3
et-xmlfile==1.1.0
fintech==6.4.4
fpdf==1.7.2
frozendict==2.0.3
future==0.18.2
hijri-converter==2.1.3
holidays==0.11.1
html5lib==1.1
idna==2.10
kombu==5.1.0
kontocheck==6.13.2
korean-lunar-calendar==0.2.1
lxml==4.6.3
netaddr==0.8.0
num2words==0.5.10
numpy==1.21.0
openpyxl==3.0.7
paho-mqtt==1.5.1
pandas==1.1.5
pdfrw==0.4
Pillow==8.1.2
prometheus-client==0.11.0
prompt-toolkit==3.0.19
psutil==5.7.3
psycopg2-binary==2.8.6
puremagic==1.10
pwnedpasswords-offline==1.1.0
pycparser==2.20
PyMeeus==0.5.11
PyNaCl==1.4.0
PyPDF2==1.26.0
pyphen==0.11.0
python-box==3.4.6
python-dateutil==2.8.1
python-dotenv==0.18.0
python-magic==0.4.24
python-stdnum==1.16
pytz==2021.1
qrcode==6.1
redis==3.5.3
requests==2.24.0
selenium==3.141.0
sentry-sdk==1.1.0
simplejson==3.17.2
six==1.16.0
sqlparse==0.4.1
tinycss2==1.1.0
toml==0.10.2
urllib3==1.25.11
vine==5.0.0
wcwidth==0.2.5
WeasyPrint==52.5
webencodings==0.5.1
whitenoise==5.2.0
wrapt==1.12.1
xlrd==2.0.1
xlwt==1.3.0
xmlschema==1.6.4
xmltodict==0.12.0
zxcvbn==4.4.28

Other Dependencies

N/A

Minimally Reproducible Test Case

Expected Behavior

The worker should run in the foreground

Actual Behavior

Exception in celery.bin.worker

worker_1 | Traceback (most recent call last):
worker_1 | File "/usr/local/bin/celery", line 8, in <module>
worker_1 | sys.exit(main())
worker_1 | File "/usr/local/lib/python3.8/site-packages/celery/__main__.py", line 15, in main
worker_1 | sys.exit(_main())
worker_1 | File "/usr/local/lib/python3.8/site-packages/celery/bin/celery.py", line 213, in main
worker_1 | return celery(auto_envvar_prefix="CELERY")
worker_1 | File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
worker_1 | return self.main(*args, **kwargs)
worker_1 | File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
worker_1 | rv = self.invoke(ctx)
worker_1 | File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
worker_1 | return _process_result(sub_ctx.command.invoke(sub_ctx))
worker_1 | File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
worker_1 | return ctx.invoke(self.callback, **ctx.params)
worker_1 | File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
worker_1 | return callback(*args, **kwargs)
worker_1 | File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
worker_1 | return f(get_current_context(), *args, **kwargs)
worker_1 | File "/usr/local/lib/python3.8/site-packages/celery/bin/base.py", line 132, in caller
worker_1 | return f(ctx, *args, **kwargs)
worker_1 | File "/usr/local/lib/python3.8/site-packages/celery/bin/worker.py", line 327, in worker
worker_1 | argv,
worker_1 | UnboundLocalError: local variable 'argv' referenced before assignment

Issue 2:
Checklist

[ x] I have checked the issues list

for similar or identical bug reports.

[ x] I have checked the pull requests list

for existing proposed fixes.

[ x] I have checked the commit log

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

[x ] I have included all related issues and possible duplicate issues in this issue

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

Related Issues and Possible Duplicates

Related Issues

None

Possible Duplicates

None

Description

I'm running celery inside a django project, from a python script. Until 5.0, I was able to run celery using worker_main() method :

from celery import Celery
app = Celery()
app.worker_main()

From the application related documentation page, nothing points out the fact that worker_main() method seems gone.

I suppose I miss something somewhere, but maybe because of some lack of clarity from documentation