Skip to content

DAG workflow canvas element - #11118

Open
chrisbarber wants to merge 38 commits into
celery:mainfrom
chrisbarber:celery-dag
Open

chrisbarber wants to merge 38 commits into
celery:mainfrom
chrisbarber:celery-dag

Conversation

@chrisbarber

@chrisbarber chrisbarber commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Discussed initially here: #893 (comment)

That comment may be the best quick and understandable orientation to what this PR implements.

Basically make minimal modifications to get a DAG workflow canvas element.

The feature is mostly proven through integration tests, which I have run against both redis and postgres backends.

I realize some docs and some basic checks to block invalid sequences of calls and give informative errors etc should be needed. But I believe the feature is overdue and that type of stuff can be added very easily during review so I really wanted to open the PR to at least to get through any technical blockers and also run the whole CI.

Also in my opinion this could be merged as some kind of beta or undocumented feature at least to avoid development stalling.

Addresses feature requests for DAG style workflow behavior, eg open issues #893, #6030, #4562 or some old closed one like #3666 or another historical one where a potential contribution unfortunately didn’t happen #5000 (comment) (~100 stars on that repo shows interest in Celery DAG capability; also note that the approach there is polling only and doesn’t integrate cleanly in contrast to this PR which does so by using the existing barrier functionality of on_chord_part_return / chord_unlock)

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.29936% with 111 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.83%. Comparing base (a2d470f) to head (1260c3e).

Files with missing lines Patch % Lines
celery/workflow.py 17.54% 94 Missing ⚠️
celery/app/task.py 22.22% 4 Missing and 3 partials ⚠️
celery/canvas.py 63.63% 2 Missing and 2 partials ⚠️
celery/app/builtins.py 71.42% 1 Missing and 1 partial ⚠️
celery/backends/base.py 83.33% 1 Missing and 1 partial ⚠️
celery/worker/request.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11118      +/-   ##
==========================================
- Coverage   91.28%   90.83%   -0.45%     
==========================================
  Files         153      154       +1     
  Lines       21824    21971     +147     
  Branches     2710     2747      +37     
==========================================
+ Hits        19921    19957      +36     
- Misses       1603     1707     +104     
- Partials      300      307       +7     
Flag Coverage Δ
unittests 90.81% <29.29%> (-0.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy
auvipy self-requested a review November 17, 2026 05:30
@auvipy auvipy added this to the 5.8.0 milestone Nov 17, 2026

@auvipy auvipy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also some CI is failing

Comment thread celery/canvas.py Resolved
@auvipy

auvipy commented Nov 17, 2026

Copy link
Copy Markdown
Member

can you also reference all relevant open or closed issue related to this which are also referenced in the issue you initially refrenced to fix? that will help us to consolidate all possible things to consider before finally moving forward with it

@auvipy

auvipy commented Nov 17, 2026

Copy link
Copy Markdown
Member

can you also check the smoke tests?

@chrisbarber

Copy link
Copy Markdown
Contributor Author

can you also check the smoke tests?

Something wrong with the import, since 0dd70dd
I’m failing so far to see the cause

  Error: 
  Unable to load celery application.
  While trying to load the module app the following error occurred:
  Traceback (most recent call last):
    File "/usr/local/lib/python3.10/site-packages/celery/bin/celery.py", line 137, in celery
      app = find_app(app)
    File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 528, in find_app
      sym = symbol_by_name(app, imp=imp)
    File "/usr/local/lib/python3.10/site-packages/kombu/utils/imports.py", line 59, in symbol_by_name
      module = imp(module_name, package=package, **kwargs)
    File "/usr/local/lib/python3.10/site-packages/celery/utils/imports.py", line 106, in import_from_cwd
      return imp(module, package=package)
    File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/app/app.py", line 13, in <module>
      from t.smoke.tasks import *
    File "/app/t/smoke/tasks.py", line 13, in <module>
      from t.integration.tasks import *  # noqa
    File "/app/t/integration/tasks.py", line 7, in <module>
      from celery import Signature, Task, chain, chord, group, shared_task, workflow
  ImportError: cannot import name 'workflow' from 'celery' (/usr/local/lib/python3.10/site-packages/celery/__init__.py)

@chrisbarber

Copy link
Copy Markdown
Contributor Author

I see, it looks like some tests deliberately mix dev and latest(pypi) workers

celery_worker: CeleryTestWorker,
celery_latest_worker: CeleryTestWorker,

Somehow I guess the t.smoke.workers.latest.CeleryLatestWorkerContainer one is picking up t/integration/tasks.py with my changes

@chrisbarber

Copy link
Copy Markdown
Contributor Author

Now some issue with tox-gh-actions

  File "/opt/hostedtoolcache/Python/3.11.16/x64/lib/python3.11/site-packages/tox_gh_actions/plugin.py", line 13, in <module>
    from tox.config.of_type import _PLACE_HOLDER
ImportError: cannot import name '_PLACE_HOLDER' from 'tox.config.of_type' (/opt/hostedtoolcache/Python/3.11.16/x64/lib/python3.11/site-packages/tox/config/of_type.py)

Anyways I put a try/except around the import to handle the “latest” (pypi) worker importing the t/integration/tasks.py file – 4b80760

A previously failing smoke test now passes locally for me so it should be sufficient. There could be a more elegant way but it could also just be removed later. I guess it’s an overall question of how to handle breaking changes in those smoke tests which mix old and new workers.

@auvipy

auvipy commented Nov 18, 2026

Copy link
Copy Markdown
Member

i guess we have to deal it separately, I had some plan for that before v5.7.0 release, will try to start that today in a separate PR

@auvipy

auvipy commented Nov 21, 2026

Copy link
Copy Markdown
Member

I found this library from a redhat engineer https://github.com/selinon/selinon I think we can get some architectural inspiration from here to make the celery DAG for futuristic and more extendable by design.

@chrisbarber

Copy link
Copy Markdown
Contributor Author

I found this library from a redhat engineer https://github.com/selinon/selinon I think we can get some architectural inspiration from here to make the celery DAG for futuristic and more extendable by design.

Sure, if someone has bandwidth.

We looked at that lib and didn’t want yaml’s, for also realtime or dynamic purposes.

I think rudimentary DAG support in Celery remedies the issue where people land on the canvas docs and assume it can handle normal workflows, only to discover that it supports only some unusual subset of topologies, and results in workflow code that is hard to read and maintain (deeply nested chain/chord/identity structures with fragile/inflexible positional argument passing).

This PR leverages the fact that Celery already has mature barrier functionality and remedies that shortcoming promptly, without forcing another dependency or unnecessarily forcing polling (like celery-dyrygent for example).

At least at our company we have used the approach like this PR in production for over a year. To be fair we added a few extra things -- in an on_failure handler we delete the failed result from the sorted set and republish the task to a “failed” queue which is normally not consumed from. Then we move those tasks onto default to let them “reprocess,” and the DAG workflows continue from where they left off. It’s maybe an extension that could also go into Celery but it might be better for a blog or something, and let people take their own approach (maybe with some hook or option though for deleting the failures from the sorted sets, as that is fairly low-level).

@auvipy

auvipy commented Nov 21, 2026

Copy link
Copy Markdown
Member

I also do not want yaml, I would prefer simple python based API as well, may be we can take some design motivation from that and use our own pythonic DAG API

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants