Muhammad huzaifa
Muhammad huzaifa

Reputation: 174

django celery error: Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")

I am perplexed,from a weird error which i have no idea as i am new to celery, this error occurs on just the setup phase, every thing is simply configured as written in the celery doc https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html the tracback is:

(env) muhammad@huzaifa:~/Desktop/practice/app$ celery -A app worker -l INFO
[2022-04-04 16:21:40,988: WARNING/MainProcess] No hostname was supplied. Reverting to default 'localhost'
[2022-04-04 16:21:40,993: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")
Traceback (most recent call last):
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 1250, in backend
    return self._local.backend
AttributeError: '_thread._local' object has no attribute 'backend'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/worker/worker.py", line 203, in start
    self.blueprint.start(self)
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/bootsteps.py", line 112, in start
    self.on_start()
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 136, in on_start
    self.emit_banner()
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 170, in emit_banner
    ' \n', self.startup_info(artlines=not use_image))),
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 232, in startup_info
    results=self.app.backend.as_uri(),
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 1252, in backend
    self._local.backend = new_backend = self._get_backend()
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 955, in _get_backend
    backend, url = backends.by_url(
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py", line 69, in by_url
    return by_name(backend, loader), url
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py", line 47, in by_name
    aliases.update(load_extension_class_names(extension_namespace))
  File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/utils/imports.py", line 146, in load_extension_class_names
    yield ep.name, ':'.join([ep.module_name, ep.attrs[0]])
AttributeError: 'EntryPoint' object has no attribute 'module_name'

the init file is:

from __future__ import absolute_import, unicode_literals

from .celery import app as celery_app

__all__ = ('celery_app',)

celery.py:

import os

from celery import Celery

# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

app = Celery('app', broker='localhost')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django apps.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print(f'Request: {self.request!r}')

For your information, rabbitmq-server is running on localhost thats why i have set BROKER_URL TO 'localhost'

 rabbitmq-server.service - RabbitMQ Messaging Server
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-04-03 16:14:04 PKT; 24h ago
   Main PID: 1005 (beam.smp)
     Status: "Initialized"
      Tasks: 91 (limit: 9090)

idk why this is happening, i have been look around for like hours and cant find a solution and not even the error on google or anywhere. any help would be greatly appreciated Thanks!

Upvotes: 8

Views: 8182

Answers (6)

Lev Slinsen
Lev Slinsen

Reputation: 448

Apparently, it's been fixed in a later update. After trying the suggested solution of downgrading celery to 5.2.3 I've ran into another issue with a different library. So instead I tried to upgrade celery to the latest version, which at the time of writing is 5.4.0, and it works fine.

Upvotes: 0

AAA
AAA

Reputation: 21

A latecomer to this. I struggled to make Celery work for a simple example and kept hitting a dead end with the following error.

AttributeError: 'EntryPoints' object has no attribute 'get'

I tried pinning versions of Kombu and Celery to 4.6 and 5.2.3 respectively as recommended by fella developers on this trail.

The only thing that finally worked for me is to hack the kombu/utils/combat.py file.

Following the trail of the error, I modified line 82 and changed the following code:

 for ep in importlib_metadata.entry_points().get(namespace, [])

to the following

for ep in importlib_metadata.entry_points(group ='namespace') 

I am sure this is not a correct approach, at least from the standpoint of view of the usage of third-party libs in projects as the modification is not from the source and hence is vulnerable to break when lib is updated, and is not advisable to fix the issue in such manner. But at least it has helped me in a POC exercise.

You can try the above if you are stuck like me. Also, I will be glad to hear, if anybody out there has any suggestion or workaround without breaking underlying principles of coding which does not involve changing a lib that could evolve in the future and break custom code.

Upvotes: 1

Swapnil .449
Swapnil .449

Reputation: 21

I encountered the same problem today. So, I just Downgraded the celery version to 5.2.3

pip install celery==5.2.3

and it worked

Upvotes: 2

Jeff G
Jeff G

Reputation: 1048

You are encountering a new bug with celery, reported here: https://github.com/celery/celery/issues/7409

The workaround you can try is to pin the versions of your dependency for celery to an older version (i.e. before release of the celery bug). For instance, my requirements.txt includes:

celery==5.2.3

or on the command line you might just be able to run

pip install celery==5.2.3

(For reference, the versions where I was seeing the error reported here were celery 5.2.5 & click 8.1.2)

Hopefully this gets fixed upstream and we can remove our version pins.

Upvotes: 14

MikeNunez.dev
MikeNunez.dev

Reputation: 11

I downgrade celery to 5.2.3 and everything work fine again.

Thank you @Jeff-G

Upvotes: 0

Richard Agrey
Richard Agrey

Reputation: 11

Encountered the same error downgraded the celery version to 5.2.0 and it worked

Upvotes: 1

Related Questions