Skip to content

Fix Signature.clone() kwargs aliasing - #10561

Closed
SIBTAIN-ASAD wants to merge 14 commits into
celery:mainfrom
SIBTAIN-ASAD:fix-signature-clone-kwargs
Closed

SIBTAIN-ASAD wants to merge 14 commits into
celery:mainfrom
SIBTAIN-ASAD:fix-signature-clone-kwargs

Conversation

@SIBTAIN-ASAD

Copy link
Copy Markdown

Signature.clone() is expected to return an independent signature when called without overrides. The no-override branch currently reuses the original kwargs dictionary, so mutating a clone can mutate the source and sibling clones.

This change deep-copies kwargs in that branch, matching the existing defensive copy of options. The regression test covers both the mapping and a nested value.

Refs #10560

Tests:

  • ./.venv/bin/python -m pytest -q t/unit/tasks/test_canvas.py -k test_clone_copies_kwargs
  • ./.venv/bin/python -m compileall -q celery/canvas.py t/unit/tasks/test_canvas.py

@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

❌ 10 Tests Failed:

Tests completed Failed Passed Skipped
2329 10 2319 20
View the top 3 failed test(s) by shortest run time
t/unit/tasks/test_stamping.py::test_canvas_stamping::test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor0]
Stack Traces | 0.004s run time
self = <t.unit.tasks.test_stamping.test_canvas_stamping object at 0x7f28e42ae660>
request = <SubRequest 'workflow' for <Function test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor0]>>
canvas_workflow = group((sig(), group([sig1()]), group((sig1(), sig2())), group(<_regen: [sig0(), sig1()]>), group([sig1(), sig2()]), group((sig1(), sig2())), sig1() | sig2(), %sig3((sig1(), sig2())), %celery.group(<_regen: [sig0(), sig1()]>, tasks=(sig3(), sig4())), %celerychord([sig1(), sig2()], kwargs={}, header=(sig3(), sig4()), body=sig5()), sig1() | group((sig2(), sig3())) | group((sig4(), sig5())), %(sig8((sig1(), group([{'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig3', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig4', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig5', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig6', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]))) | group((sig9(), sig10())))))

    @pytest.fixture(params=["stamped_canvas", "stamped_linked_canvas"])
    def workflow(self, request, canvas_workflow: Signature) -> Signature:
>       return request.getfixturevalue(request.param)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../unit/tasks/test_stamping.py:619: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:630: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:726: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1232: in execute
    result: FixtureValue = ihook.pytest_fixture_setup(
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:53: in run_old_style_hookwrapper
    return result.get_result()
           ^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:38: in run_old_style_hookwrapper
    res = yield
          ^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/_pytest/setuponly.py:36: in pytest_fixture_setup
    return (yield)
            ^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1328: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1005: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^
.../unit/tasks/test_stamping.py:605: in stamped_canvas
    workflow.stamp(CleanupVisitor())
celery/canvas.py:1742: in stamp
    task.stamp(visitor, append_stamps, **headers)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'task': 'sig1', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False} | {'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}
visitor = <t.unit.tasks.test_stamping.CleanupVisitor object at 0x7f28e4f84590>
append_stamps = False, headers = {'stamped_headers': []}

    def stamp(self, visitor=None, append_stamps=False, **headers):
        visitor_headers = None
        if visitor is not None:
            visitor_headers = visitor.on_chain_start(self, **headers) or {}
        headers = self._stamp_headers(visitor_headers, append_stamps, **headers)
        self.stamp_links(visitor, **headers)
    
        for task in self.tasks:
>           task.stamp(visitor, append_stamps, **headers)
            ^^^^^^^^^^
E           AttributeError: 'dict' object has no attribute 'stamp'

celery/canvas.py:1176: AttributeError
t/unit/tasks/test_stamping.py::test_canvas_stamping::test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor1]
Stack Traces | 0.004s run time
self = <t.unit.tasks.test_stamping.test_canvas_stamping object at 0x7f28e42affb0>
request = <SubRequest 'workflow' for <Function test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor1]>>
canvas_workflow = group((sig(), group([sig1()]), group((sig1(), sig2())), group(<_regen: [sig0(), sig1()]>), group([sig1(), sig2()]), group((sig1(), sig2())), sig1() | sig2(), %sig3((sig1(), sig2())), %celery.group(<_regen: [sig0(), sig1()]>, tasks=(sig3(), sig4())), %celerychord([sig1(), sig2()], kwargs={}, header=(sig3(), sig4()), body=sig5()), sig1() | group((sig2(), sig3())) | group((sig4(), sig5())), %(sig8((sig1(), group([{'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig3', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig4', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig5', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig6', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]))) | group((sig9(), sig10())))))

    @pytest.fixture(params=["stamped_canvas", "stamped_linked_canvas"])
    def workflow(self, request, canvas_workflow: Signature) -> Signature:
>       return request.getfixturevalue(request.param)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../unit/tasks/test_stamping.py:619: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:630: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:726: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1232: in execute
    result: FixtureValue = ihook.pytest_fixture_setup(
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:53: in run_old_style_hookwrapper
    return result.get_result()
           ^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:38: in run_old_style_hookwrapper
    res = yield
          ^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/_pytest/setuponly.py:36: in pytest_fixture_setup
    return (yield)
            ^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1328: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1005: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^
.../unit/tasks/test_stamping.py:605: in stamped_canvas
    workflow.stamp(CleanupVisitor())
celery/canvas.py:1742: in stamp
    task.stamp(visitor, append_stamps, **headers)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'task': 'sig1', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False} | {'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}
visitor = <t.unit.tasks.test_stamping.CleanupVisitor object at 0x7f28d96d23f0>
append_stamps = False, headers = {'stamped_headers': []}

    def stamp(self, visitor=None, append_stamps=False, **headers):
        visitor_headers = None
        if visitor is not None:
            visitor_headers = visitor.on_chain_start(self, **headers) or {}
        headers = self._stamp_headers(visitor_headers, append_stamps, **headers)
        self.stamp_links(visitor, **headers)
    
        for task in self.tasks:
>           task.stamp(visitor, append_stamps, **headers)
            ^^^^^^^^^^
E           AttributeError: 'dict' object has no attribute 'stamp'

celery/canvas.py:1176: AttributeError
t/unit/tasks/test_stamping.py::test_canvas_stamping::test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor2]
Stack Traces | 0.004s run time
self = <t.unit.tasks.test_stamping.test_canvas_stamping object at 0x7f28e42ccda0>
request = <SubRequest 'workflow' for <Function test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor2]>>
canvas_workflow = group((sig(), group([sig1()]), group((sig1(), sig2())), group(<_regen: [sig0(), sig1()]>), group([sig1(), sig2()]), group((sig1(), sig2())), sig1() | sig2(), %sig3((sig1(), sig2())), %celery.group(<_regen: [sig0(), sig1()]>, tasks=(sig3(), sig4())), %celerychord([sig1(), sig2()], kwargs={}, header=(sig3(), sig4()), body=sig5()), sig1() | group((sig2(), sig3())) | group((sig4(), sig5())), %(sig8((sig1(), group([{'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig3', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig4', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig5', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig6', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]))) | group((sig9(), sig10())))))

    @pytest.fixture(params=["stamped_canvas", "stamped_linked_canvas"])
    def workflow(self, request, canvas_workflow: Signature) -> Signature:
>       return request.getfixturevalue(request.param)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../unit/tasks/test_stamping.py:619: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:630: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:726: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1232: in execute
    result: FixtureValue = ihook.pytest_fixture_setup(
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:53: in run_old_style_hookwrapper
    return result.get_result()
           ^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:38: in run_old_style_hookwrapper
    res = yield
          ^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/_pytest/setuponly.py:36: in pytest_fixture_setup
    return (yield)
            ^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1328: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1005: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^
.../unit/tasks/test_stamping.py:605: in stamped_canvas
    workflow.stamp(CleanupVisitor())
celery/canvas.py:1742: in stamp
    task.stamp(visitor, append_stamps, **headers)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'task': 'sig1', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False} | {'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}
visitor = <t.unit.tasks.test_stamping.CleanupVisitor object at 0x7f28d9638170>
append_stamps = False, headers = {'stamped_headers': []}

    def stamp(self, visitor=None, append_stamps=False, **headers):
        visitor_headers = None
        if visitor is not None:
            visitor_headers = visitor.on_chain_start(self, **headers) or {}
        headers = self._stamp_headers(visitor_headers, append_stamps, **headers)
        self.stamp_links(visitor, **headers)
    
        for task in self.tasks:
>           task.stamp(visitor, append_stamps, **headers)
            ^^^^^^^^^^
E           AttributeError: 'dict' object has no attribute 'stamp'

celery/canvas.py:1176: AttributeError
t/unit/tasks/test_stamping.py::test_canvas_stamping::test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor3]
Stack Traces | 0.004s run time
self = <t.unit.tasks.test_stamping.test_canvas_stamping object at 0x7f28e4ec3680>
request = <SubRequest 'workflow' for <Function test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor3]>>
canvas_workflow = group((sig(), group([sig1()]), group((sig1(), sig2())), group(<_regen: [sig0(), sig1()]>), group([sig1(), sig2()]), group((sig1(), sig2())), sig1() | sig2(), %sig3((sig1(), sig2())), %celery.group(<_regen: [sig0(), sig1()]>, tasks=(sig3(), sig4())), %celerychord([sig1(), sig2()], kwargs={}, header=(sig3(), sig4()), body=sig5()), sig1() | group((sig2(), sig3())) | group((sig4(), sig5())), %(sig8((sig1(), group([{'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig3', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig4', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig5', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig6', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]))) | group((sig9(), sig10())))))

    @pytest.fixture(params=["stamped_canvas", "stamped_linked_canvas"])
    def workflow(self, request, canvas_workflow: Signature) -> Signature:
>       return request.getfixturevalue(request.param)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../unit/tasks/test_stamping.py:619: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:630: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:726: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1232: in execute
    result: FixtureValue = ihook.pytest_fixture_setup(
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:53: in run_old_style_hookwrapper
    return result.get_result()
           ^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:38: in run_old_style_hookwrapper
    res = yield
          ^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/_pytest/setuponly.py:36: in pytest_fixture_setup
    return (yield)
            ^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1328: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1005: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^
.../unit/tasks/test_stamping.py:605: in stamped_canvas
    workflow.stamp(CleanupVisitor())
celery/canvas.py:1742: in stamp
    task.stamp(visitor, append_stamps, **headers)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'task': 'sig1', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False} | {'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}
visitor = <t.unit.tasks.test_stamping.CleanupVisitor object at 0x7f28d96398e0>
append_stamps = False, headers = {'stamped_headers': []}

    def stamp(self, visitor=None, append_stamps=False, **headers):
        visitor_headers = None
        if visitor is not None:
            visitor_headers = visitor.on_chain_start(self, **headers) or {}
        headers = self._stamp_headers(visitor_headers, append_stamps, **headers)
        self.stamp_links(visitor, **headers)
    
        for task in self.tasks:
>           task.stamp(visitor, append_stamps, **headers)
            ^^^^^^^^^^
E           AttributeError: 'dict' object has no attribute 'stamp'

celery/canvas.py:1176: AttributeError
t/unit/tasks/test_stamping.py::test_canvas_stamping::test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor4]
Stack Traces | 0.004s run time
self = <t.unit.tasks.test_stamping.test_canvas_stamping object at 0x7f28e42cce90>
request = <SubRequest 'workflow' for <Function test_stamp_in_options[stamped_canvas-canvas_workflow11-stamping_visitor4]>>
canvas_workflow = group((sig(), group([sig1()]), group((sig1(), sig2())), group(<_regen: [sig0(), sig1()]>), group([sig1(), sig2()]), group((sig1(), sig2())), sig1() | sig2(), %sig3((sig1(), sig2())), %celery.group(<_regen: [sig0(), sig1()]>, tasks=(sig3(), sig4())), %celerychord([sig1(), sig2()], kwargs={}, header=(sig3(), sig4()), body=sig5()), sig1() | group((sig2(), sig3())) | group((sig4(), sig5())), %(sig8((sig1(), group([{'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig3', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig4', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig5', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig6', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]))) | group((sig9(), sig10())))))

    @pytest.fixture(params=["stamped_canvas", "stamped_linked_canvas"])
    def workflow(self, request, canvas_workflow: Signature) -> Signature:
>       return request.getfixturevalue(request.param)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../unit/tasks/test_stamping.py:619: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:630: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:726: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1232: in execute
    result: FixtureValue = ihook.pytest_fixture_setup(
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:53: in run_old_style_hookwrapper
    return result.get_result()
           ^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:38: in run_old_style_hookwrapper
    res = yield
          ^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/_pytest/setuponly.py:36: in pytest_fixture_setup
    return (yield)
            ^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1328: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1005: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^
.../unit/tasks/test_stamping.py:605: in stamped_canvas
    workflow.stamp(CleanupVisitor())
celery/canvas.py:1742: in stamp
    task.stamp(visitor, append_stamps, **headers)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'task': 'sig1', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False} | {'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}
visitor = <t.unit.tasks.test_stamping.CleanupVisitor object at 0x7f28d966aa20>
append_stamps = False, headers = {'stamped_headers': []}

    def stamp(self, visitor=None, append_stamps=False, **headers):
        visitor_headers = None
        if visitor is not None:
            visitor_headers = visitor.on_chain_start(self, **headers) or {}
        headers = self._stamp_headers(visitor_headers, append_stamps, **headers)
        self.stamp_links(visitor, **headers)
    
        for task in self.tasks:
>           task.stamp(visitor, append_stamps, **headers)
            ^^^^^^^^^^
E           AttributeError: 'dict' object has no attribute 'stamp'

celery/canvas.py:1176: AttributeError
t/unit/tasks/test_stamping.py::test_canvas_stamping::test_stamp_in_options[stamped_linked_canvas-canvas_workflow11-stamping_visitor0]
Stack Traces | 0.015s run time
self = <t.unit.tasks.test_stamping.test_canvas_stamping object at 0x7f28e439fb60>
request = <SubRequest 'workflow' for <Function test_stamp_in_options[stamped_linked_canvas-canvas_workflow11-stamping_visitor0]>>
canvas_workflow = group((sig(), group([sig1()]), group((sig1(), sig2())), group(<_regen: [sig0(), sig1()]>), group([sig1(), sig2()]), group((sig1(), sig2())), sig1() | sig2(), %sig3((sig1(), sig2())), %celery.group(<_regen: [sig0(), sig1()]>, tasks=(sig3(), sig4())), %celerychord([sig1(), sig2()], kwargs={}, header=(sig3(), sig4()), body=sig5()), sig1() | group((sig2(), sig3())) | group((sig4(), sig5())), %(sig8((sig1(), group([{'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig3', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig4', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]), group([{'task': 'sig5', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}, {'task': 'sig6', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}]))) | group((sig9(), sig10())))))

    @pytest.fixture(params=["stamped_canvas", "stamped_linked_canvas"])
    def workflow(self, request, canvas_workflow: Signature) -> Signature:
>       return request.getfixturevalue(request.param)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.../unit/tasks/test_stamping.py:619: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:630: in getfixturevalue
    fixturedef = self._get_active_fixturedef(argname)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:726: in _get_active_fixturedef
    fixturedef.execute(request=subrequest)
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1232: in execute
    result: FixtureValue = ihook.pytest_fixture_setup(
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:53: in run_old_style_hookwrapper
    return result.get_result()
           ^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12....../site-packages/pluggy/_callers.py:38: in run_old_style_hookwrapper
    res = yield
          ^^^^^
.tox/3.12-unit/lib/python3.12.../site-packages/_pytest/setuponly.py:36: in pytest_fixture_setup
    return (yield)
            ^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1328: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/3.12-unit/lib/python3.12.............../site-packages/_pytest/fixtures.py:1005: in call_fixture_func
    fixture_result = fixturefunc(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^
.../unit/tasks/test_stamping.py:612: in stamped_linked_canvas
    workflow.stamp(CleanupVisitor())
celery/canvas.py:1742: in stamp
    task.stamp(visitor, append_stamps, **headers)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'task': 'sig1', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False} | {'task': 'sig2', 'args': (), 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False}
visitor = <t.unit.tasks.test_stamping.CleanupVisitor object at 0x7f28d36cbaa0>
append_stamps = False, headers = {'stamped_headers': []}

    def stamp(self, visitor=None, append_stamps=False, **headers):
        visitor_headers = None
        if visitor is not None:
            visitor_headers = visitor.on_chain_start(self, **headers) or {}
        headers = self._stamp_headers(visitor_headers, append_stamps, **headers)
        self.stamp_links(visitor, **headers)
    
        for task in self.tasks:
>           task.stamp(visitor, append_stamps, **headers)
            ^^^^^^^^^^
E           AttributeError: 'dict' object has no attribute 'stamp'

celery/canvas.py:1176: AttributeError
t/unit/tasks/test_canvas.py::test_chord::test_flag_allow_error_cb_on_chord_header
Stack Traces | 0.083s run time
contains 1 failed subtest
t/unit/tasks/test_canvas.py::test_chain::test_group_in_center_of_chain
Stack Traces | 0.134s run time
self = <t.unit.tasks.test_canvas.test_chain object at 0x7f28e4f5b6b0>

    def test_group_in_center_of_chain(self):
        t1 = chain(self.add.si(1, 1), group(self.add.si(1, 1), self.add.si(1, 1)),
                   self.add.si(1, 1) | self.add.si(1, 1))
        t2 = chord([self.add.si(1, 1), self.add.si(1, 1)], t1)
>       t2.freeze()  # should not raise
        ^^^^^^^^^^^

.../unit/tasks/test_canvas.py:1048: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
celery/canvas.py:2169: in freeze
    body_result = self.body.freeze(
celery/canvas.py:1161: in freeze
    _, results = self._frozen = self.prepare_steps(
celery/canvas.py:1308: in prepare_steps
    res = task.freeze(
celery/canvas.py:2162: in freeze
    header_result = self.tasks.freeze(
celery/canvas.py:1953: in freeze
    return self.app.GroupResult(*self._freeze_group_tasks(
           ^^^^^^^^^^^^^^^^^^^^
celery/local.py:144: in __getattr__
    return getattr(self._get_current_object(), name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <celery.contrib.testing.app.Trap object at 0x7f28d390d4f0>
name = 'GroupResult'

    def __getattr__(self, name):
        # Workaround to allow unittest.mock to patch this object
        # in Python 3.8 and above.
        if name == '_is_coroutine' or name == '__func__':
            return None
        print(name)
>       raise RuntimeError('Test depends on current_app')
E       RuntimeError: Test depends on current_app

.../contrib/testing/app.py:37: RuntimeError
t/unit/tasks/test_canvas.py::test_chord::test_freeze_tasks_body_is_group[group_subclass]
Stack Traces | 0.134s run time
self = <t.unit.tasks.test_canvas.test_chord object at 0x7f28e437c650>
subtests = <_pytest.subtests.Subtests object at 0x7f28dad11910>
group_type = <class 't.unit.tasks.test_canvas.group_subclass'>

    @pytest.mark.parametrize("group_type", [group,  group_subclass])
    def test_freeze_tasks_body_is_group(self, subtests, group_type):
        # Confirm that `group index` values counting up from 0 are set for
        # elements of a chord's body when the chord is encapsulated in a group
        body_elem = self.add.s()
        chord_body = group_type([body_elem] * 42)
        chord_obj = chord(self.add.s(), body=chord_body)
        top_group = group_type([chord_obj])
    
        # We expect the body to be the signature we passed in before we freeze
        with subtests.test(msg="Validate body type and tasks are retained"):
            assert isinstance(chord_obj.body, group_type)
            assert all(
                embedded_body_elem is body_elem
                for embedded_body_elem in chord_obj.body.tasks
            )
        # We also expect the body to have no initial options - since all of the
        # embedded body elements are confirmed to be `body_elem` this is valid
        assert body_elem.options == {}
        # When we freeze the chord, its body will be cloned and options set
>       top_group.freeze()

.../unit/tasks/test_canvas.py:1920: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
celery/canvas.py:1953: in freeze
    return self.app.GroupResult(*self._freeze_group_tasks(
celery/canvas.py:1942: in _freeze_group_tasks
    results = list(self._freeze_unroll(
celery/canvas.py:2004: in _freeze_unroll
    yield task.freeze(group_id=group_id,
celery/canvas.py:2169: in freeze
    body_result = self.body.freeze(
celery/canvas.py:1953: in freeze
    return self.app.GroupResult(*self._freeze_group_tasks(
           ^^^^^^^^^^^^^^^^^^^^
celery/local.py:144: in __getattr__
    return getattr(self._get_current_object(), name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <celery.contrib.testing.app.Trap object at 0x7f28d2e307d0>
name = 'GroupResult'

    def __getattr__(self, name):
        # Workaround to allow unittest.mock to patch this object
        # in Python 3.8 and above.
        if name == '_is_coroutine' or name == '__func__':
            return None
        print(name)
>       raise RuntimeError('Test depends on current_app')
E       RuntimeError: Test depends on current_app

.../contrib/testing/app.py:37: RuntimeError
t/unit/tasks/test_canvas.py::test_chord::test_freeze_tasks_body_is_group[group]
Stack Traces | 0.145s run time
self = <t.unit.tasks.test_canvas.test_chord object at 0x7f28e437c320>
subtests = <_pytest.subtests.Subtests object at 0x7f28d2e33050>
group_type = <class 'celery.canvas.group'>

    @pytest.mark.parametrize("group_type", [group,  group_subclass])
    def test_freeze_tasks_body_is_group(self, subtests, group_type):
        # Confirm that `group index` values counting up from 0 are set for
        # elements of a chord's body when the chord is encapsulated in a group
        body_elem = self.add.s()
        chord_body = group_type([body_elem] * 42)
        chord_obj = chord(self.add.s(), body=chord_body)
        top_group = group_type([chord_obj])
    
        # We expect the body to be the signature we passed in before we freeze
        with subtests.test(msg="Validate body type and tasks are retained"):
            assert isinstance(chord_obj.body, group_type)
            assert all(
                embedded_body_elem is body_elem
                for embedded_body_elem in chord_obj.body.tasks
            )
        # We also expect the body to have no initial options - since all of the
        # embedded body elements are confirmed to be `body_elem` this is valid
        assert body_elem.options == {}
        # When we freeze the chord, its body will be cloned and options set
>       top_group.freeze()

.../unit/tasks/test_canvas.py:1920: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
celery/canvas.py:1953: in freeze
    return self.app.GroupResult(*self._freeze_group_tasks(
celery/canvas.py:1942: in _freeze_group_tasks
    results = list(self._freeze_unroll(
celery/canvas.py:2004: in _freeze_unroll
    yield task.freeze(group_id=group_id,
celery/canvas.py:2169: in freeze
    body_result = self.body.freeze(
celery/canvas.py:1953: in freeze
    return self.app.GroupResult(*self._freeze_group_tasks(
           ^^^^^^^^^^^^^^^^^^^^
celery/local.py:144: in __getattr__
    return getattr(self._get_current_object(), name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <celery.contrib.testing.app.Trap object at 0x7f28d2e332c0>
name = 'GroupResult'

    def __getattr__(self, name):
        # Workaround to allow unittest.mock to patch this object
        # in Python 3.8 and above.
        if name == '_is_coroutine' or name == '__func__':
            return None
        print(name)
>       raise RuntimeError('Test depends on current_app')
E       RuntimeError: Test depends on current_app

.../contrib/testing/app.py:37: RuntimeError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@auvipy

auvipy commented Sep 5, 2026

Copy link
Copy Markdown
Member

can you please check the test failures and fix them?

@auvipy
auvipy requested review from auvipy and a lite review from Copilot September 5, 2026 09:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

clone() can still alias self.kwargs when called with args/opts overrides but no kwargs (via _merge() returning self.kwargs), leaving the same mutation hazard in other common clone call patterns.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes Signature.clone() so a no-override clone does not share the original .kwargs mapping, preventing mutations on a clone from affecting the source signature (and sibling clones). This aligns kwargs handling with the existing defensive deepcopy() already applied to options.

Changes:

  • Deep-copy self.kwargs in the clone() no-overrides branch.
  • Add a regression test asserting both top-level kwargs and a nested value are independent.
File summaries
File Description
celery/canvas.py Deep-copies kwargs in Signature.clone() when called with no overrides to avoid aliasing.
t/unit/tasks/test_canvas.py Adds regression coverage for clone() kwargs independence, including nested structures.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread celery/canvas.py Outdated
Comment on lines +457 to +461
@@ -458,7 +458,7 @@ def clone(self, args=None, kwargs=None, **opts):
if args or kwargs or opts:
args, kwargs, opts = self._merge(args, kwargs, opts)
else:
args, kwargs, opts = self.args, self.kwargs, self.options
args, kwargs, opts = self.args, deepcopy(self.kwargs), self.options

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.

@SIBTAIN-ASAD please cross check and fix this

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.

did you also checked this?

@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

Thanks — I checked the Codecov failures. The reported failures are the existing current_app Trap failures in unrelated canvas tests; the focused clone coverage passes locally. I also addressed the remaining aliasing path when clone receives args or option overrides without kwargs by deep-copying the merged kwargs, and added regression coverage for that case. Pushed as 513a7d6; the checks are rerunning now.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Deep-copying generator-backed group kwargs eagerly exhausts their lazy task iterator.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread celery/canvas.py Outdated
kwargs = deepcopy(kwargs)
else:
args, kwargs, opts = self.args, self.kwargs, self.options
args, kwargs, opts = self.args, deepcopy(self.kwargs), self.options

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.

@SIBTAIN-ASAD please fix this

@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

I found the lazy-generator regression and fixed it in d90ac6e. clone() now preserves lazy _regen inputs while still deep-copying ordinary nested kwargs, so group(generator).clone() does not advance the generator. I added a regression test for that behavior; the focused clone tests now pass (3 passed, 213 deselected), and compileall plus git diff --check are clean.

@auvipy

auvipy commented Sep 6, 2026

Copy link
Copy Markdown
Member

@Namraa310806 @phanky1 would you mind review this?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Deep-copying nested signatures converts them to dictionaries, breaking cloned map, starmap, and chunks canvases.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread celery/canvas.py
for value in kwargs.values()
if isinstance(value, _regen)
}
return deepcopy(kwargs, memo)

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.

@SIBTAIN-ASAD please cross check and fix

@auvipy

auvipy commented Sep 6, 2026

Copy link
Copy Markdown
Member

also the unit tests are failing

@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

I found the nested-signature issue as well and fixed it in 55d5912. Clone kwargs now preserve lazy _regen inputs and explicitly clone nested Signature values, so map, starmap, and chunks keep their task signatures instead of turning them into plain dicts. I added regression coverage for all three canvas types. Focused clone tests pass (6 passed, 213 deselected), and the scoped pre-commit hooks, compileall, and diff checks are clean.

@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

The latest run confirms the remaining pre-commit failure is still unrelated: flake8 reports E301 at t/unit/app/test_schedules.py:161, outside this PR. The scoped hooks pass locally, the six clone regressions pass, and Read the Docs is green. The unit failures are the existing current_app Trap failures in unrelated canvas tests; no failure points to the clone changes.

@auvipy
auvipy requested a lite review from Copilot September 6, 2026 17:25
@auvipy auvipy added this to the 5.7.0 milestone Sep 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

_deepcopy_kwargs()’s pre-walk currently has no cycle detection and can recurse infinitely on self-referential containers in kwargs, causing a crash before deepcopy() can handle cycles.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread celery/canvas.py
Comment on lines +77 to +90
memo = {}

def collect(value):
if isinstance(value, _regen):
memo[id(value)] = value
elif isinstance(value, Signature):
memo[id(value)] = value.clone()
elif isinstance(value, dict):
for nested_value in value.values():
collect(nested_value)
elif isinstance(value, (list, tuple, set, frozenset)):
for nested_value in value:
collect(nested_value)

@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

I also addressed the cycle-safety review in 80c1f3e. _deepcopy_kwargs now tracks visited containers, so self-referential kwargs are copied without recursion errors while lazy generators and nested signatures remain preserved. I added regression coverage; the focused clone tests pass (7 passed, 213 deselected), and the scoped pre-commit hooks, compileall, and diff checks are clean.

@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

The new 80c1f3e workflows are currently marked action_required with no jobs, so they appear to be waiting for maintainer approval of fork-originated execution. Once approved, I will recheck the full matrix; the local scoped suite and hooks are already green.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Generator-backed children, signature-containing cycles, and signatures inside unsupported containers remain incorrectly cloned.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

celery/canvas.py:82

  • Could we preserve child-signature independence while keeping this lazy? Memoizing the _regen object itself avoids eager consumption, but group.from_dict() only wraps that same iterator with maybe_signature(..., clone=False). Consequently, a generator-backed group's clone yields the exact same child Signature objects as the source (and sibling clones), so mutating a child through the clone still mutates the original. A lazy wrapper that clones/deep-copies each item as it is yielded would retain laziness without reintroducing aliasing; the regression test should also assert that the yielded child is distinct.
        if isinstance(value, _regen):
            memo[id(value)] = value

celery/canvas.py:98

  • Could nested Signature handling avoid depending on this fixed container whitelist? For example, with kwargs={'items': collections.deque([child_sig])}, collect() never reaches child_sig; the subsequent deepcopy() invokes Signature.__deepcopy__, which returns a plain dict, so cloning silently changes the task argument's type and behavior. The same occurs for signatures stored in custom containers/object attributes; handling Signature through the deepcopy protocol rather than a pre-scan would cover those valid object graphs.
        elif isinstance(value, (list, tuple, set, frozenset)):
            value_id = id(value)
            if value_id in seen:
                return
            seen.add(value_id)
            for nested_value in value:
                collect(nested_value)
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread celery/canvas.py Outdated
Comment on lines +83 to +84
elif isinstance(value, Signature):
memo[id(value)] = value.clone()
@SIBTAIN-ASAD

Copy link
Copy Markdown
Author

I addressed the remaining cloning edge cases in 15cb4cc. Lazy group clones now yield independent child signatures without consuming the source iterator; nested Signatures are preserved through arbitrary containers and signature cycles; and the pre-walk remains cycle-safe. Added regression coverage for all three cases. Focused canvas coverage passes (9 passed, 213 deselected), plus scoped pre-commit, compileall, and diff checks.

@auvipy

auvipy commented Sep 7, 2026

Copy link
Copy Markdown
Member

can you also add smoke test for this? and possibly integration test?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Nested signatures can still lose nested values or required subclass state during cloning.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread celery/canvas.py
Comment on lines +85 to +93
clone = type(value).__new__(type(value))
memo[value_id] = clone
dict.__init__(clone)
collect(value)
for key, nested_value in value.items():
dict.__setitem__(clone, deepcopy(key, memo), deepcopy(nested_value, memo))
clone._app = value._app
if '_type' in value.__dict__:
clone._type = value._type

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.

@SIBTAIN-ASAD please fix the test failures along with this suggestions. or you can leave this pr for more experienced contributors

Comment thread celery/canvas.py Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@auvipy

auvipy commented Sep 7, 2026

Copy link
Copy Markdown
Member

@phanky1 may be you can retake this if possible

@auvipy

auvipy commented Sep 7, 2026

Copy link
Copy Markdown
Member

closing in favor of #10571

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.

3 participants