Skip to content

Conversation

@dfm88
Copy link
Contributor

@dfm88 dfm88 commented Jun 27, 2025

@auvipy I've added tests for pr #9740.
fixes #9738

Original PR changes

  • simple safer access to parent_task.request

Tests Added

  • Unit tests in t/unit/tasks/test_tasks.py
  • Integration tests in t/integration/test_tasks.py
  • Both cover single task execution and nested parent-child relationships (3 levels deep)
  • Added edge case testing for parent tasks without root_id

The tests are quite similar between unit and integration - we could avoid the copy-paste with a global conftest, but there isn't one and it's probably not necessary for this simple case.

Canvas Operations Limitation

However, the current solution won't work for canvas operations (chain, group, chord) like it does with apply_async. For example:

# This won't have proper root/parent IDs:
chain(task1.s(), task2.s(), task3.s()).apply()

The issue is that canvas classes have their own apply() methods in canvas.py that don't establish the proper ID context before calling individual tasks. The fix only handles the basic task.apply() method, but canvas operations bypass this.

For full canvas support, the methods in canvas.py::_chain::apply(), canvas.py::group::apply() and canvas.py::_chord: apply(), classes would need similar updates to establish the ID hierarchy like their apply_async methods do.

@codecov
Copy link

codecov bot commented Jun 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.62%. Comparing base (9cb389d) to head (6893d71).
⚠️ Report is 44 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9784   +/-   ##
=======================================
  Coverage   78.61%   78.62%           
=======================================
  Files         153      153           
  Lines       19172    19178    +6     
  Branches     2539     2540    +1     
=======================================
+ Hits        15073    15079    +6     
  Misses       3807     3807           
  Partials      292      292           
Flag Coverage Δ
unittests 78.60% <100.00%> (+<0.01%) ⬆️

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

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

@auvipy
Copy link
Member

auvipy commented Jun 27, 2025

thanks dude

@auvipy auvipy requested review from auvipy and Copilot June 27, 2025 10:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds and verifies eager .apply() behavior by propagating parent_id and root_id on task requests.

  • Introduces unit and integration tests for single-task and nested apply() calls, including handling when a parent has no root_id.
  • Updates Task.apply() to populate parent_id and root_id in the eager request payload.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
t/unit/tasks/test_tasks.py Added unit tests for eager .apply() ID propagation
t/integration/test_tasks.py Added integration tests for eager .apply() ID propagation
celery/app/task.py Populates parent_id and root_id in Task.apply() requests
Comments suppressed due to low confidence (2)

t/integration/test_tasks.py:498

  • Test classes need to be named with an uppercase Test prefix (e.g. TestApplyTasks) for pytest to discover their methods.
class test_apply_tasks:

t/integration/test_tasks.py:498

  • We should also add tests for canvas operations (e.g. chain(...).apply(), group(...).apply(), chord(...).apply()) to ensure they set parent_id and root_id correctly.
class test_apply_tasks:

@auvipy auvipy changed the title Issue 9738 tests Issue 9738 : Add root_id and parent_id to .apply() Jun 27, 2025
@auvipy auvipy changed the title Issue 9738 : Add root_id and parent_id to .apply() Fix #9738 : Add root_id and parent_id to .apply() Jun 27, 2025
@auvipy auvipy added this to the 5.6.0 milestone Jun 27, 2025
@auvipy
Copy link
Member

auvipy commented Jun 27, 2025

is it possible to improve / increase unit test coverage?

@dfm88
Copy link
Contributor Author

dfm88 commented Jun 27, 2025

is it possible to improve / increase unit test coverage?

Ok I'll check the output of pytest-cov

@dfm88
Copy link
Contributor Author

dfm88 commented Jun 27, 2025

All modified and coverable lines are covered by tests ✅

Actually I don't know how to increase coverage for these specific changes since they seems to bee all covered by new tests

CodeCov

@auvipy
Copy link
Member

auvipy commented Jun 27, 2025

oh sorry no need

@auvipy auvipy merged commit a83070e into celery:main Jul 3, 2025
233 of 235 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add root_id & parent_id for tasks executed with ".apply()"

2 participants