Repository navigation
Description
Checklist
- I have verified that the issue exists against the
masterbranch 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 reportin 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
masterbranch of Celery. - I have included the contents of
pip freezein 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
- https://groups.google.com/g/celery-users/c/3Z07zPfUZQ0/m/VpOCC2PGDQAJ
- (semi-related but different) Exchange type headers and chords #6690
Possible Duplicates
- None
Environment & Settings
Celery version: 5.1.1
celery report Output:
(celery_movies) C:\Users\markb\PycharmProjects\celery_movies>celery -A celery_movies report
software -> celery:5.1.1 (sun-harmonics) kombu:5.1.0 py:3.7.2
billiard:3.6.4.0 py-amqp:5.0.6
platform -> system:Windows arch:32bit, WindowsPE
kernel version:10 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:file:///C:/Users/markb/tmp
Exchange: <class 'kombu.entity.Exchange'>
Queue: <class 'kombu.entity.Queue'>
imports: ['celery_movies.tasks']
task_acks_late: True
task_default_exchange: 'my_exchange'
task_queues: [<unbound Queue movies -> <unbound Exchange my_exchange(direct)> -> movies>]
task_routes: {
'movies.': {'queue': 'movies'}, 'news.': {'queue': 'news'}}
deprecated_settings: None
broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'file:///C:/Users/markb/tmp'
(celery_news) C:\Users\markb\PycharmProjects\celery_news>celery -A celery_news report
software -> celery:5.1.1 (sun-harmonics) kombu:5.1.0 py:3.7.2
billiard:3.6.4.0 py-amqp:5.0.6
platform -> system:Windows arch:32bit, WindowsPE
kernel version:10 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:file:///C:/Users/markb/tmp
Exchange: <class 'kombu.entity.Exchange'>
Queue: <class 'kombu.entity.Queue'>
imports: ['celery_news.tasks']
task_acks_late: True
task_default_exchange: 'my_exchange'
task_queues: [<unbound Queue news -> <unbound Exchange my_exchange(direct)> -> news>,
<unbound Queue celery -> <unbound Exchange my_exchange(direct)> -> celery>]
task_routes: {
'movies.': {'queue': 'movies'}, 'news.': {'queue': 'news'}}
deprecated_settings: None
broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'file:///C:/Users/markb/tmp'
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:
Other Dependencies
Details
amqp==5.0.6 billiard==3.6.4.0 cached-property==1.5.2 celery==5.1.1 click==7.1.2 click-didyoumean==0.0.3 click-plugins==1.1.1 click-repl==0.2.0 importlib-metadata==4.6.1 kombu==5.1.0 prompt-toolkit==3.0.19 pytz==2021.1 six==1.16.0 typing-extensions==3.10.0.0 vine==5.0.0 wcwidth==0.2.5 zipp==3.5.0
Minimally Reproducible Test Case
Details
Worker #1 celery.py (launched via: celery -A celery_movies worker -l info --pool=solo)
from celery.app import Celery
from celery_movies import celeryconfig
broker_url = 'amqp://'
celery_app = Celery('movies')
celery_app.config_from_object(celeryconfig)
celery_app.conf.update(broker_url=broker_url,
result_backend="file:///C:/Users/markb/tmp")celeryconfig.py
from kombu.common import Queue, Exchange
imports = ['celery_movies.tasks']
task_acks_late = True
task_default_exchange = "my_exchange"
task_queues = [Queue('movies', exchange=Exchange(name=task_default_exchange), routing_key='movies')
]
task_routes = {
'movies.*': {'queue': 'movies'},
'news.*': {'queue': 'news'}
}tasks.py
from celery_movies.celery import celery_app
@celery_app.task(name='movies.task.publish_movie', bind=True)
def publish_movie(self, *args, **kwargs):
print("publishing movie")Worker #2
celery.py (launched via: celery -A celery_news worker -l info --pool=solo)
from celery.app import Celery
from celery_news import celeryconfig
broker_url = 'amqp://'
celery_app = Celery('news')
celery_app.config_from_object(celeryconfig)
celery_app.conf.update(broker_url=broker_url,
result_backend="file:///C:/Users/markb/tmp")celeryconfig.py
from kombu.common import Queue, Exchange
imports = ['celery_news.tasks']
task_acks_late = True
task_default_exchange = "my_exchange"
task_queues = [Queue('news', exchange=Exchange(name=task_default_exchange), routing_key='news'),
Queue('celery', exchange=Exchange(name=task_default_exchange), routing_key='celery')]
task_routes = {
'movies.*': {'queue': 'movies'},
'news.*': {'queue': 'news'}
}tasks.py
from celery_news.celery import celery_app
@celery_app.task(name='news.task.publish_news', bind=True)
def publish_news(self, *args, **kwargs):
print("publishing news")trigger_flow.py
from celery import group, chain
import uuid
from celery.app import Celery
from celery_movies import celeryconfig
broker_url = 'amqp://'
celery_app = Celery('movies')
celery_app.config_from_object(celeryconfig)
celery_app.conf.update(broker_url=broker_url,
result_backend="file:///C:/Users/markb/tmp")
movie_task = celery_app.signature('movies.task.publish_movie', task_id=str(uuid.uuid4()), immutable=True)
news_task = celery_app.signature('news.task.publish_news', task_id=str(uuid.uuid4()), immutable=True)
my_chord = chain(movie_task,
group(movie_task.set(task_id=str(uuid.uuid4())), movie_task.set(task_id=str(uuid.uuid4()))),
news_task)
my_chord.apply_async()Expected Behavior
I expect my first task to be handled by the Movies worker, then the chord to start executing the two grouped movie tasks via the Movies worker, and then finally the News worker should pick up and execute the news task
Actual Behavior
First task is handled by the Movies worker, but when the Movies worker tries to move on to the Chord (Group + Chain was upgraded to Chord), system chunks on attempting to submit the chord_unlock task.
[2021-07-07 20:01:48,298: WARNING/MainProcess] C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py:659: RuntimeWarning: Exception raised outside body: Task of kind 'news.task.publish_news' never registered, please make sure it's imported.:
Traceback (most recent call last):
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 70, in __get__
return obj_dict[name]
KeyError: 'type'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py", line 515, in trace_task
priority=task_priority
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1416, in apply_async
return self.run(tasks, body, args, task_id=task_id, **merged_options)
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1488, in run
max_retries=max_retries,
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 657, in apply_chord
self.fallback_chord_unlock(header_result, body, **kwargs)
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 642, in fallback_chord_unlock
queue = body.options.get('queue', getattr(body.type, 'queue', None))
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\kombu\utils\objects.py", line 29, in __get__
return super().__get__(instance, owner)
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 74, in __get__
return obj_dict.setdefault(name, self.func(obj))
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 498, in type
return self._type or self.app.tasks[self['task']]
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\registry.py", line 18, in __missing__
raise self.NotRegistered(key)
celery.exceptions.NotRegistered: 'news.task.publish_news'
exc, exc_info.traceback)))
[2021-07-07 20:01:48,300: ERROR/MainProcess] Task movies.task.publish_movie[f734ecc4-d174-41c3-b0dd-96544b9815a3] raised unexpected: Task of kind 'news.task.publish_news' never registered, please make sure it's imported.
Traceback (most recent call last):
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 70, in __get__
return obj_dict[name]
KeyError: 'type'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py", line 515, in trace_task
priority=task_priority
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1416, in apply_async
return self.run(tasks, body, args, task_id=task_id, **merged_options)
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1488, in run
max_retries=max_retries,
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 657, in apply_chord
self.fallback_chord_unlock(header_result, body, **kwargs)
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 642, in fallback_chord_unlock
queue = body.options.get('queue', getattr(body.type, 'queue', None))
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\kombu\utils\objects.py", line 29, in __get__
return super().__get__(instance, owner)
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 74, in __get__
return obj_dict.setdefault(name, self.func(obj))
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 498, in type
return self._type or self.app.tasks[self['task']]
File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\registry.py", line 18, in __missing__
raise self.NotRegistered(key)
celery.exceptions.NotRegistered: 'news.task.publish_news'
This is because the task signatures have no body.type attribute set so a KeyError ends up being thrown when executing the queue = line (and the priority = line)
def fallback_chord_unlock(self, header_result, body, countdown=1,
**kwargs):
kwargs['result'] = [r.as_tuple() for r in header_result]
queue = body.options.get('queue', getattr(body.type, 'queue', None))
priority = body.options.get('priority', getattr(body.type, 'priority', 0))
self.app.tasks['celery.chord_unlock'].apply_async(
(header_result.id, body,), kwargs,
countdown=countdown,
queue=queue,
priority=priority,
)I believe a solution could be the following, but i'm not confident this doesnt impact something else in Celery
def fallback_chord_unlock(self, header_result, body, countdown=1,
**kwargs):
kwargs['result'] = [r.as_tuple() for r in header_result]
body_type = body.get('type', None)
queue = body.options.get('queue', getattr(body_type, 'queue', None))
priority = body.options.get('priority', getattr(body_type, 'priority', 0))
self.app.tasks['celery.chord_unlock'].apply_async(
(header_result.id, body,), kwargs,
countdown=countdown,
queue=queue,
priority=priority,
)
Activity
open-collective-bot commentedon Jul 8, 2021
Hey @ghoulmaster 👋,
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.
auvipy commentedon Jul 8, 2021
the PR fix the error?
ghoulmaster commentedon Jul 8, 2021
Yes, but pr needs a little work. Will work on it later