Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Celery Import Error #7783

Closed
Tracked by #7605
marimuthuei opened this issue Oct 3, 2022 · 22 comments · Fixed by #7785 or #7835
Closed
Tracked by #7605

Celery Import Error #7783

marimuthuei opened this issue Oct 3, 2022 · 22 comments · Fixed by #7785 or #7835
Milestone

Comments

@marimuthuei
Copy link

Not able to import Celery module when creating simple app.

from celery import Celery
ImportError: cannot import name 'Celery' from 'celery'

Additonal info:
This issue doesn't occur when we downgrade importlib-metadata to 4.12.0
Env details
image

@open-collective-bot
Copy link

Hey @marimuthuei 👋,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our Open Collective and consider backing us - every little helps!

We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.

@woutdenolf
Copy link
Contributor

What python version? Seems to occur only with python 3.7 #7784

@woutdenolf
Copy link
Contributor

Ok I guess because importlib-metadata is not installed when you install celery in a python 3.8 environment.

@ppanero
Copy link

ppanero commented Oct 3, 2022

similar imports are failing (e.g. current_app) with the same behavior (works when downgrading importlib-metadata). Seems to only be in python 3.7.

Tests with py3.8 and importlib-metadata works for me.

@marimuthuei
Copy link
Author

its python3.7 env

@woutdenolf
Copy link
Contributor

This seems to be the cause: python/importlib_metadata#405

Successfully installed importlib_metadata-4.13.0
$ python
Python 3.7.9 (default, Jul  5 2021, 22:17:33) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib_metadata import entry_points
>>> entry_points().get("celery.result_backends", list())
__main__:1: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
[]

So I guess we should fix

def load_extension_class_names(namespace):
for ep in entry_points().get(namespace, []):
yield ep.name, ep.value

@woutdenolf
Copy link
Contributor

@woutdenolf
Copy link
Contributor

Made a fix for celery (#7785) and kombu (celery/kombu#1601).

@woutdenolf
Copy link
Contributor

woutdenolf commented Oct 3, 2022

importlib-metadata<5.0 is an alternative solution: #7782 and celery/kombu#1602

@marimuthuei
Copy link
Author

@auvipy Can this issue will be resolved in celery ==4.4.7 version?

@auvipy auvipy added this to the 5.3 milestone Oct 12, 2022
@auvipy
Copy link
Member

auvipy commented Oct 12, 2022

nope

@jaraco
Copy link

jaraco commented Oct 15, 2022

@auvipy Can this issue will be resolved in celery ==4.4.7 version?

As mentioned above, pinning to importlib_metadata < 5 in your environment should work around the issue while keeping celery == 4.4.7.

@Nusnus
Copy link
Member

Nusnus commented Oct 18, 2022

Hey guys, the PR associated with this issue introduced a bug and the documentation cannot be built.
Relevant commit: f77e98a
Doc build error from this PR: https://readthedocs.org/projects/celery/builds/18287948/

Please revert until a proper fix is available, we cannot have breaking code in master.
@woutdenolf @auvipy

@auvipy
Copy link
Member

auvipy commented Oct 19, 2022

Hey nusnus, the actual PR was squashed merged a4545db , the commit you are refering should have the fix with the commit merged a4545db . but if it still have the element of failure, we will revert to fix it.

@woutdenolf
Copy link
Contributor

https://readthedocs.org/projects/celery/builds/18287948/

  File "/home/docs/checkouts/readthedocs.org/user_builds/celery/envs/7785/lib/python3.7/site-packages/kombu/utils/compat.py", line 82, in entrypoints
    for ep in importlib_metadata.entry_points().get(namespace, [])
AttributeError: 'EntryPoints' object has no attribute 'get'

But we capture AttributeError

try:
    _entry_points = entry_points().get(namespace, [])
except AttributeError:
    _entry_points = entry_points().select(group=namespace)

So maybe you're looking at an old CI run?

@auvipy
Copy link
Member

auvipy commented Oct 19, 2022

https://readthedocs.org/projects/celery/builds/18287948/

  File "/home/docs/checkouts/readthedocs.org/user_builds/celery/envs/7785/lib/python3.7/site-packages/kombu/utils/compat.py", line 82, in entrypoints
    for ep in importlib_metadata.entry_points().get(namespace, [])
AttributeError: 'EntryPoints' object has no attribute 'get'

But we capture AttributeError

try:
    _entry_points = entry_points().get(namespace, [])
except AttributeError:
    _entry_points = entry_points().select(group=namespace)

So maybe you're looking at an old CI run?

i have opened a revert pr, there the doc build is still failing, can you cross check please?

@woutdenolf
Copy link
Contributor

Ah wait:

  File "/home/docs/checkouts/readthedocs.org/user_builds/celery/envs/7785/lib/python3.7/site-packages/kombu/utils/compat.py", line 82, in entrypoints
    for ep in importlib_metadata.entry_points().get(namespace, [])
AttributeError: 'EntryPoints' object has no attribute 'get'

This is an error from kombu. So it won't pass until we release kombu (fixed in celery/kombu#1601).

@auvipy
Copy link
Member

auvipy commented Oct 19, 2022

oh i see! a new beta of kombu should be released, I will do that

@thedrow thedrow mentioned this issue Oct 19, 2022
12 tasks
@auvipy
Copy link
Member

auvipy commented Oct 19, 2022

#7834 testing

@woutdenolf
Copy link
Contributor

woutdenolf commented Oct 19, 2022

Apart from kombu, it seems readthedocs was not using requirements/docs.txt. This fixes the doc building: #7835

@Nusnus
Copy link
Member

Nusnus commented Oct 19, 2022

Thank you @woutdenolf for investigating this and coming up with a solution quickly! Appreciate it. Hope it will get merged soon :)

@titusfx
Copy link

titusfx commented Jan 12, 2023

@jaraco downgrading importlib_metadata didn't work for me :(

In my case, I had a file that was called queue.py

matthewfeickert added a commit to yadage/packtivity that referenced this issue Feb 9, 2023
* Fix requires a new release of kombu
   - c.f. celery/celery#7783 (comment)
   - This should be viewed as temporary. As soon as there is a new release of kombu
     the release with this fix in in should get yanked in favor of a new release
     without this restriction.
* Add lower bound of celery>=5.0.0.
mattbennett added a commit to mattbennett/nameko that referenced this issue Feb 9, 2023
importlib-metadata is not on later versions of python, so we can use
a conditional pin. see # celery/celery#7783
mattbennett added a commit to nameko/nameko that referenced this issue Feb 9, 2023
* fix flakiness in publish retry tests

not clear how this ever passed. it's unhelpfully tied to the kombu
implementation which probably means it's a bad test, but just fixing
it up for now

* upgrade isort

* rename whitelist -> allowlist

* upgrade moto and pyjwt

* bump requests to resolve conflict with boto

* pyjwt requires you to specify algorithm now

* upgrade urllib to resolve dependency tree

* expected retries isn't flakey; depends on version of kombu

* update import following deprecation, removes warning

* pytest arg --strict renamed to --strict-markers

* import sort

* no cover pragmas for kombu version conditionals

* pyjwt and moto require older versions on py2

* run docs on ubuntu 20.04; drop 3.6 from matrix

* put 3.6 back and try all on 20.04

* drop 3.6 again

* sort 5.12.0 not available on py3.7

* pin down jinja

to a releaase that is still compatible with our old version of sphinx.
it's not worth trying to upgrade sphinx because the new docs use mkdocs

* importlib-metadata 5.0 is not compatible with latest kombu on py3.7

importlib-metadata is not on later versions of python, so we can use
a conditional pin. see # celery/celery#7783

* upgrade pinned version of eventlet

fixes https://stackoverflow.com/questions/75137717/eventlet-dns-python-attribute-error-module-dns-rdtypes-has-no-attribute-any

* whoops; fix syntax in setup.py

* oldest eventlet on py3.10 needs updating too

* match "pinned" requests to the one in dev reqs

also choose a version that works on all currently supported pythons

* refactor conditional to avoid another pragma

* copy/paste snafu

* try running tests on ubuntu latest
mattbennett added a commit to mattbennett/nameko that referenced this issue Feb 9, 2023
* fix flakiness in publish retry tests

not clear how this ever passed. it's unhelpfully tied to the kombu
implementation which probably means it's a bad test, but just fixing
it up for now

* upgrade isort

* rename whitelist -> allowlist

* upgrade moto and pyjwt

* bump requests to resolve conflict with boto

* pyjwt requires you to specify algorithm now

* upgrade urllib to resolve dependency tree

* expected retries isn't flakey; depends on version of kombu

* update import following deprecation, removes warning

* pytest arg --strict renamed to --strict-markers

* import sort

* no cover pragmas for kombu version conditionals

* pyjwt and moto require older versions on py2

* run docs on ubuntu 20.04; drop 3.6 from matrix

* put 3.6 back and try all on 20.04

* drop 3.6 again

* sort 5.12.0 not available on py3.7

* pin down jinja

to a releaase that is still compatible with our old version of sphinx.
it's not worth trying to upgrade sphinx because the new docs use mkdocs

* importlib-metadata 5.0 is not compatible with latest kombu on py3.7

importlib-metadata is not on later versions of python, so we can use
a conditional pin. see # celery/celery#7783

* upgrade pinned version of eventlet

fixes https://stackoverflow.com/questions/75137717/eventlet-dns-python-attribute-error-module-dns-rdtypes-has-no-attribute-any

* whoops; fix syntax in setup.py

* oldest eventlet on py3.10 needs updating too

* match "pinned" requests to the one in dev reqs

also choose a version that works on all currently supported pythons

* refactor conditional to avoid another pragma

* copy/paste snafu

* try running tests on ubuntu latest
# Conflicts:
#	docs/examples/test/test_examples.py
#	nameko/cli/__init__.py
#	nameko/cli/utils/__init__.py
#	nameko/rpc.py
#	nameko/testing/pytest.py
#	test/amqp/test_publish.py
pvital added a commit to instana/python-sensor that referenced this issue Mar 8, 2023
importlib_metadata package removed deprecated entry_point interfaces on
version 5.0.0 [1] , and this change impacts celery >= 5.2.7 [2] running
with python 3.7.X (it doesn't impact >= 3.8). For this reason, we
control celery and importlib_metadata versions on python 3.7
environments.
[1] python/importlib_metadata#405
[2] celery/celery#7783

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
pvital added a commit to instana/python-sensor that referenced this issue Mar 8, 2023
importlib_metadata package removed deprecated entry_point interfaces on
version 5.0.0 [1] , and this change impacts celery >= 5.2.7 [2] running
with python 3.7.X (it doesn't impact >= 3.8). For this reason, we
control celery and importlib_metadata versions on python 3.7
environments.
[1] python/importlib_metadata#405
[2] celery/celery#7783

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Ferenc- pushed a commit to instana/python-sensor that referenced this issue Mar 8, 2023
importlib_metadata package removed deprecated entry_point interfaces on
version 5.0.0 [1] , and this change impacts celery >= 5.2.7 [2] running
with python 3.7.X (it doesn't impact >= 3.8). For this reason, we
control celery and importlib_metadata versions on python 3.7
environments.
[1] python/importlib_metadata#405
[2] celery/celery#7783

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants