<p dir="auto">(<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/celery/celery/commit/56a6246c74cd4ed51d12194cf3627b0bdf066bc5/hovercard" href="https://github.com/celery/celery/commit/56a6246c74cd4ed51d12194cf3627b0bdf066bc5"><tt>56a6246</tt></a> introduces a bug in 5.0.x, that is present in 5.0.6 but was not in 5.0.5. The line with <code class="notranslate">return detach(...</code> needs to be indented one step further, otherwise it's outside of the <code class="notranslate">if ...</code> block and <code class="notranslate">argv</code> is undefined. The issue is not present in the master branch.)</p>

<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" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.  <strong>It does not, it's in 5.0.6 only</strong></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://groups.google.com/forum/#!forum/celery-users" rel="nofollow">discussion group</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="http://docs.celeryproject.org/en/latest/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/master">commit log</a><br>
to find out if the bug was already fixed in the master 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"> 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" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.  <strong>It does not</strong></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"> 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>: 5.0.6</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>
<ol dir="auto">
<li>Run <code class="notranslate">celery -A proj worker</code> (note: no <code class="notranslate">-D</code>)</li>
</ol>
<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>: 5.0.6</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="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"><pre class="notranslate"><code class="notranslate">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
</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>

<p dir="auto">The worker should run in the foreground</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">Exception in celery.bin.worker</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="worker_1       | Traceback (most recent call last):
worker_1       |   File &quot;/usr/local/bin/celery&quot;, line 8, in &lt;module&gt;
worker_1       |     sys.exit(main())
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/celery/__main__.py&quot;, line 15, in main
worker_1       |     sys.exit(_main())
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/celery/bin/celery.py&quot;, line 213, in main
worker_1       |     return celery(auto_envvar_prefix=&quot;CELERY&quot;)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/click/core.py&quot;, line 829, in __call__
worker_1       |     return self.main(*args, **kwargs)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/click/core.py&quot;, line 782, in main
worker_1       |     rv = self.invoke(ctx)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/click/core.py&quot;, line 1259, in invoke
worker_1       |     return _process_result(sub_ctx.command.invoke(sub_ctx))
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/click/core.py&quot;, line 1066, in invoke
worker_1       |     return ctx.invoke(self.callback, **ctx.params)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/click/core.py&quot;, line 610, in invoke
worker_1       |     return callback(*args, **kwargs)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/click/decorators.py&quot;, line 21, in new_func
worker_1       |     return f(get_current_context(), *args, **kwargs)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/celery/bin/base.py&quot;, line 132, in caller
worker_1       |     return f(ctx, *args, **kwargs)
worker_1       |   File &quot;/usr/local/lib/python3.8/site-packages/celery/bin/worker.py&quot;, line 327, in worker
worker_1       |     argv,
worker_1       | UnboundLocalError: local variable 'argv' referenced before assignment"><pre class="notranslate"><code class="notranslate">worker_1       | Traceback (most recent call last):
worker_1       |   File "/usr/local/bin/celery", line 8, in &lt;module&gt;
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
</code></pre></div>
<h1 dir="auto">Checklist</h1>

<ul dir="auto">
<li>[ x] I have checked the <a href="https://github.com/celery/celery/issues?utf8=%E2%9C%93&amp;q=is%3Aissue+label%3A%22Category%3A+Documentation%22+">issues list</a><br>
for similar or identical bug reports.</li>
<li>[ x] I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li>[ x] I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li>[x ] I have included all related issues and possible duplicate issues in this issue<br>
(If there are none, check this box anyway).</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>
<h1 dir="auto">Description</h1>
<p dir="auto">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 :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from celery import Celery
app = Celery()
app.worker_main()"><pre class="notranslate"><code class="notranslate">from celery import Celery
app = Celery()
app.worker_main()
</code></pre></div>
<p dir="auto">From the <a href="https://docs.celeryproject.org/en/stable/userguide/application.html" rel="nofollow">application related documentation page</a>, nothing points out the fact that worker_main() method seems gone.</p>
<p dir="auto">I suppose I miss something somewhere, but maybe because of some lack of clarity from documentation</p>