Skip to content

group.skew() removes all tasks if group input is generator #4298

Closed

Description

@allanlei

Checklist

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).

    python 3.6.2
    celery==4.1.0
    amqp==2.2.1
    billiard==3.5.0.3
    
  • I have verified that the issue exists against the master branch of Celery.
    As of be55de6

Steps to reproduce

@celery.task(bind=True)
def noop(task):
    pass
  1. group = celery.group(noop.si() for i in range(10))
  2. group.skew() -> group(<empty>)
  3. group.apply_async() or group() -> <GroupResult: 66fd517e-123b-4299-8cbe-9183b3f02626 []>

Expected behavior

<GroupResult: d610c923-e939-4199-9bb7-7bc89daa2ccb [9152bd60-f815-4bbe-a407-a003db34b19d, 7fc2d0ac-72ab-48b1-9083-be0f3b50b00d, d7c0a00a-85c3-4780-88f9-23be8da6fb73, 3737944f-91a4-4886-95c6-4960ef4764a7, a8da96ea-d2c4-4876-8026-e0c24c7d508a, 83ee5316-fb2f-472b-8e94-284144f92438, 5715a751-f28d-4deb-ac15-114854570fde, bc1646bf-cec9-4740-8e74-411d7b66dcca, 337aa1f3-5606-45b2-af68-5c5527289019, f5fffb98-f2f5-4423-a656-8c1d7e93291a]>

Actual behavior

<GroupResult: 66fd517e-123b-4299-8cbe-9183b3f02626 []>

Notes

If you print(group)(or something that evaluates self.tasks) before calling group.skew(), it works normally.

Activity

  1. auvipy commented on Dec 19, 2017

    @auvipy
    Member

    could you plz check the master if it still exists?

  2. added this to the milestone on Dec 19, 2017
  3. allanlei commented on Dec 28, 2017

    @allanlei
    ContributorAuthor

    Yes. Still happening as of 2547666

  4. auvipy commented on Jan 15, 2018

    @auvipy
    Member

    any workaround?

  5. moggers87 commented on Mar 29, 2018

    @moggers87

    I believe this is a bug in celery.utils.functional.regen. Compare the outputs of regen on 4.1.0 (which has this bug) and 3.1.25 (which doesn't):

    On Celery 4.1.0:

    In [1]: from celery.utils.functional import regen        
    
    In [2]: gen = regen(i for i in range(10))                
    
    In [3]: [i for i in gen]    
    Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]                   
    
    In [4]: [i for i in gen]    
    Out[4]: []  
    

    On Celery 3.1.25:

    In [1]: from celery.utils.functional import regen        
    
    In [2]: gen = regen(i for i in range(10))                
    
    In [3]: [i for i in gen]                                 
    Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]                   
    
    In [4]: [i for i in gen]                                 
    Out[4]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]                   
    
    In [5]: [i for i in gen]                                 
    Out[5]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]   
    

    Looking at 9982773 it would appear that __consumed doesn't get updated inside __iter__.

    Doing print(group) first makes things work as expected because __getitem__ is called and populates __consumed correctly. Then subsequent calls to __iter__ work as expected too.

    A more proper workaround is to either only pass lists and tuples to group, or if you're using something like Task.chunks, reassign tasks with a list, e.g.:

    mytask.chunks(range(10), 2).group()
    mytask.tasks = list(mytask.tasks)
    mytask.skew(step=15)
    

    Finally, #4459 will (probably) fix this issue too. @auvipy would you mind adding tests for this bug into your PR? Or if you prefer, I can open a separate PR that addresses this issue only.

  6. auvipy commented on Mar 29, 2018

    @auvipy
    Member

    plz proceed with the tests

  7. modified the milestones: , v4.3 on May 27, 2018
  8. self-assigned this
    on Nov 17, 2018
  9. modified the milestones: v4.3, v5.0.0 on Jan 8, 2019
  10. modified the milestones: v5.0.0, 4.4.0 on May 6, 2019
  11. 1 remaining item

  12. modified the milestones: 4.5, 4.4.x on Dec 16, 2019
  13. mohsen-mahmoodi commented on Nov 17, 2020

    @mohsen-mahmoodi

    Same issue:

    celery==5.0.2
    
  14. assigned and unassigned on Nov 20, 2020
  15. modified the milestones: 4.4.x, 5.0.3 on Nov 20, 2020
  16. auvipy commented on Nov 20, 2020

    @auvipy
    Member

    @maybe-sybr would be great if you could also take a look here when possible

  17. maybe-sybr commented on Dec 8, 2020

    @maybe-sybr
    Contributor

    I traced this back to get repro on the originally reported versions as well as current master (420e393). Worth noting that I made the mistake of thinking it was fixed because I was printing the tasks in the group between steps in the MRTC in this issue's summary to see what was going on. Doing so concretises the generator underlying the _regen instance. Here's my new MRTC which needs a backend running for the task submission if the expected behaviour is to be observed:

    import celery
    
    app = celery.Celery(name="app")
    
    @app.task(bind=True)
    def noop(self):
        pass
    
    def gen():
        #assert False
        yield from (noop.si() for i in range(10))
    
    g = celery.group(gen())
    # Uncomment this to see the correct behaviour - but you'll need a backend
    # running since that'll mean we acually have tasks to submit.
    #print(g.tasks)
    gs = g.skew()
    r = g()
    print(repr(r))

    #4298 (comment) is correct in that this is breakage in _regen which has already been fixed in #4459 and #6112, but neither have been merged. I'd like to see the targeted fix pulled out of those PRs and merged to close this issue rather than waiting on the more complex PR to be done. I'll do that when I have some time in the next day or so.

  18. added a commit that references this issue on Dec 13, 2020
    9f9c899
  19. added 2 commits that reference this issue on Jan 11, 2021
    2cc9722
    f524566
  20. added a commit that references this issue on Jan 12, 2021
    7dc76ff
  21. added a commit that references this issue on Aug 25, 2021
    336edc6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions