Skip to content

Exchange type headers and chords #6690

Closed

Description

@brmzkw

Chords are not working with exchanges of type headers because the method fallback_chord_unlock doesn't forward headers to the unlock tasks.

To reproduce:

import celery
from celery import Celery, chord
from celery.canvas import Signature
from kombu import Exchange, Queue


app = Celery(
    'example',
    broker='amqp://guest:guest@rabbitmq//',
    backend='db+postgresql://celery:celery@postgres/celery',
)


app.conf['CELERY_QUEUES'] = (
    Queue('my_queue',
          exchange=Exchange('my_exchange', type='headers'),
          binding_arguments={'my_header': 'my_value'}),
)

app.conf['CELERY_CREATE_MISSING_QUEUES'] = False
app.conf.CELERY_DEFAULT_QUEUE = 'my_queue'

@app.task
def add(x, y):
    print('add %s and %s' % (x, y))
    return x + y

@app.task
def total(values):
    print('sum called with', values)
    return True


def main():
    sig = Signature(
        'example.add',
        args=[1, 1],
        headers={
            'my_header': 'my_value',
        }
    )

    sig2 = Signature(
        'example.add',
        args=[2, 2],
        headers={
            'my_header': 'my_value',
        }
    )

    sig_total = Signature(
        'example.total',
        headers={
            'my_header': 'my_value',
        }
    )

    chord([sig, sig2])(sig_total)

if __name__ == '__main__':
    main()

A naive fix is to add headers=body.options.get('headers') to self.app.tasks['celery.chord_unlock'].apply_async() in fallback_chord_unlock().

From my understanding, it should be broken too for direct exchanges because the routing_key is not forwarded too.

This is broken since at least 3.1.26post2.

Activity

  1. open-collective-bot commented on Mar 23, 2021

    @open-collective-bot

    Hey @brmzkw 👋,
    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.

  2. brmzkw commented on Mar 23, 2021

    @brmzkw
    Author

    As you requested on IRC, ping @xirdneh

  3. modified the milestones: 5.1.0, 5.2 on May 4, 2021
  4. modified the milestones: 5.2, 5.2.x on Oct 31, 2021
  5. modified the milestones: 5.2.x, 5.3.x on Jun 29, 2022
  6. modified the milestones: 5.3.x, 5.5 on Jun 25, 2024
  7. modified the milestones: 5.5.0, 5.7.0 on Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions