Skip to content

EagerResult shouldn't care if sync subtasks are enabled - #7253

Open
treszkai wants to merge 4 commits into
celery:mainfrom
treszkai:eager-result-get-dont-assert
Open

treszkai wants to merge 4 commits into
celery:mainfrom
treszkai:eager-result-get-dont-assert

Conversation

@treszkai

Copy link
Copy Markdown
Contributor

Description

EagerResult.get() shouldn't check if it is executed in an async context (Unlike AsyncResult.get().)

The version on master prevents a chain from being executed eagerly because _chain.apply() runs result.get() on the result of each task in the chain. As this result is an EagerResult, this get() operation fails.

I don't see the purpose of EagerResult ever disabling synchronous subtasks, but maybe I'm missing something.

Alternative

If that conditional check in EagerResult.get() is correct, then result.get() could be called with disable_sync_subtasks=False in _chain.apply().

@treszkai treszkai changed the title EagerResult doesn't care if sync subtasks are enabled EagerResult shouldn't care if sync subtasks are enabled Jan 23, 2022
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch from 36bfd66 to d8cfeac Compare January 23, 2022 20:12
@codecov

codecov Bot commented Jan 23, 2022 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.75%. Comparing base (d6fa93d) to head (dd0c952).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7253      +/-   ##
==========================================
- Coverage   88.76%   88.75%   -0.01%     
==========================================
  Files         153      153              
  Lines       19949    19946       -3     
  Branches     2331     2330       -1     
==========================================
- Hits        17707    17704       -3     
  Misses       1945     1945              
  Partials      297      297              
Flag Coverage Δ
unittests 88.73% <ø> (-0.01%) ⬇️

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.

@lgtm-com

lgtm-com Bot commented Jan 23, 2022

Copy link
Copy Markdown

This pull request introduces 25 alerts and fixes 1 when merging d8cfeac into fdb4af3 - view on LGTM.com

new alerts:

  • 12 for Wrong number of arguments in a call
  • 10 for Clear-text logging of sensitive information
  • 2 for Wrong name for an argument in a call
  • 1 for `__eq__` not overridden when adding attributes

fixed alerts:

  • 1 for Wrong name for an argument in a class instantiation

@auvipy
auvipy requested a review from a team January 24, 2022 02:30
@auvipy

auvipy commented Jan 24, 2022

Copy link
Copy Markdown
Member

@thedrow need your insight here

@auvipy auvipy added this to the 5.2.x milestone Jan 24, 2022
@treszkai

Copy link
Copy Markdown
Contributor Author

@thedrow Do you see a need to ever prevent calling .get() on an EagerResult in an async task?

Comment thread celery/result.py Resolved
@auvipy auvipy modified the milestones: 5.2.x, 5.3 Feb 16, 2022

@thedrow thedrow 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.

I haven't read through the code yet but the fundamental problem is that some tasks can run eagerly by forcing them specifically to run eagerly and others can be delayed. If the configuration alone controlled whether a task is applied or applied asynchronously, we could do something like what you're suggesting.

treszkai pushed a commit to treszkai/celery that referenced this pull request Feb 28, 2022
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch 3 times, most recently from d8cfeac to 5319658 Compare March 1, 2022 12:44
treszkai pushed a commit to treszkai/celery that referenced this pull request Mar 1, 2022
Documentation of EagerResult.get copied from AsyncResult.get, with following changes:
- changed first line
- removed warning about sync subtasks
- removed warning about backend storing the results
- changed description of disable_sync_subtasks parameter
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch from 5319658 to 4f9e579 Compare March 1, 2022 14:57
@lgtm-com

lgtm-com Bot commented Mar 1, 2022

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 4f9e579 into df7795f - view on LGTM.com

new alerts:

  • 1 for Non-exception in 'except' clause

@treszkai
treszkai requested a review from thedrow March 22, 2022 10:30
@auvipy
auvipy requested review from a team December 27, 2022 14:37
@Nusnus Nusnus modified the milestones: 5.3, Future Feb 19, 2023
@auvipy
auvipy requested review from Copilot and removed request for thedrow March 3, 2026 14:27
@celery celery deleted a comment from lgtm-com Bot Mar 3, 2026
@celery celery deleted a comment from lgtm-com Bot Mar 3, 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.

Pull request overview

This PR adjusts Celery’s eager execution result handling so that EagerResult.get() no longer enforces the “sync subtasks will block” guard (which is appropriate for AsyncResult.get() but breaks eager chains).

Changes:

  • Remove the assert_will_not_block() behavior from EagerResult.get().
  • Deprecate/ignore disable_sync_subtasks for EagerResult.get() and emit a deprecation warning when it’s passed.
  • Update the unit test for EagerResult.get() accordingly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
celery/result.py Changes EagerResult.get() semantics to not enforce sync-subtask blocking checks; adds a deprecation warning path.
t/unit/tasks/test_result.py Updates the EagerResult get() unit test to reflect the new behavior.
Comments suppressed due to low confidence (4)

t/unit/tasks/test_result.py:964

  • EagerResult is being instantiated with arguments in the wrong order: EagerResult(id, ret_value, state, traceback=None). Passing EagerResult(tid, 'x', 'x', states.SUCCESS) sets state='x' and traceback=states.SUCCESS, so get() won't return the expected value. Update the constructor call to pass states.SUCCESS as the state (and assert get() returns 'x' to validate behavior).
        self.raising = raising

    def test_wait_raises(self):

celery/result.py:1006

  • The docstring argument name is inconsistent with the actual parameter (disable_sync_subtasks) and appears to be a typo (disable_sync_subtask). Update the docstring so the parameter name matches the signature, and consider noting that the argument is deprecated/ignored.
        self.on_ready(self)

    def then(self, callback, on_error=None, weak=False):
        return self.on_ready.then(callback, on_error)

celery/result.py:1013

  • EagerResult.get now emits a CDeprecationWarning when disable_sync_subtasks is passed. There’s no unit test asserting this warning behavior (e.g., via pytest.deprecated_call / pytest.warns), so a future change could unintentionally remove or alter it without detection.
    def __reduce__(self):
        return self.__class__, self.__reduce_args__()

    def __reduce_args__(self):

celery/result.py:1013

  • EagerResult.get() now warns whenever disable_sync_subtasks is provided, but internal callers like ResultSet.join()/GroupResult.get() always pass disable_sync_subtasks through explicitly. This can lead to unexpected deprecation warnings in eager mode even when user code never passes the option to EagerResult.get() directly. Consider only warning when a non-default value is passed (e.g., False) or removing the warning to avoid warning spam from internal calls.
    def __reduce__(self):
        return self.__class__, self.__reduce_args__()

    def __reduce_args__(self):

@treszkai treszkai left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ChickenBenny Thanks for the thorough review. Fixed according to your requests.

Comment thread celery/result.py Resolved
Comment thread celery/result.py Outdated
Comment on lines +1055 to +1057
warnings.warn(
'Passing `disable_sync_subtasks` to EagerResult.get has no effect.',
CDeprecationWarning, stacklevel=2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ChickenBenny Very true.

Stack inspection turned out fairly concise, so now implemented and tested.

As such, @auvipy's (and Copilot's) fix of warning only when disable_sync_subtasks is False turned out unnecessary.

treszkai added a commit to treszkai/celery that referenced this pull request Apr 2, 2026
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch from 3132608 to 6a8f308 Compare April 2, 2026 00:53
treszkai added a commit to treszkai/celery that referenced this pull request Apr 3, 2026
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch from f5a70f2 to 144cacf Compare April 3, 2026 22:27
treszkai added a commit to treszkai/celery that referenced this pull request Apr 3, 2026
stack[1].filename != __file__ failed on Windows
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch from cb35091 to 144cacf Compare April 3, 2026 23:15
treszkai added a commit to treszkai/celery that referenced this pull request Apr 3, 2026
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch 2 times, most recently from 1473d96 to 144cacf Compare April 3, 2026 23:55
@auvipy
auvipy requested a review from Nusnus April 4, 2026 05:56
treszkai added a commit to treszkai/celery that referenced this pull request Apr 6, 2026
It technically wasn't a deprecation anyhow, as EagerResult subclassed AsyncResult, so the keyword argument is there to stay.
@auvipy auvipy removed this from v5.3 Apr 18, 2026
@auvipy
auvipy requested a review from Copilot April 18, 2026 09:15

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.

Pull request overview

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

Comment thread celery/result.py Resolved
- documentation of EagerResult.get inspired by AsyncResult.get
- remove unused `remaining` assignment in ResultSet.join
- old `test_get` (from 2017) assigned `states.SUCCESS` to `traceback`, not `state` (fixed)
@treszkai
treszkai force-pushed the eager-result-get-dont-assert branch from e951cf7 to 61c56b3 Compare April 20, 2026 11:59
@treszkai

Copy link
Copy Markdown
Contributor Author

@auvipy Rebased and squashed commits.

@auvipy

auvipy commented Apr 22, 2026

Copy link
Copy Markdown
Member

is this PR related to this? #8070

@treszkai

Copy link
Copy Markdown
Contributor Author

@auvipy Yes, #8070 is the very same issue, and same fix but for the docstring and test changes (which that issue doesn't yet deal with).

@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.

@Nusnus need your final call here

@treszkai

Copy link
Copy Markdown
Contributor Author

@auvipy @Nusnus This PR fixes #6072

@auvipy auvipy modified the milestones: 5.7.0, 5.8.0 Aug 26, 2026

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.

6 participants