Skip to content

TypeError: unhashable type: 'GroupResult' raised when building graph #4791

Closed

Description

@xirdneh

Checklist

Celery report

software -> celery:4.2.0rc4 (windowlicker) kombu:4.2.1 py:3.6.5
billiard:3.5.0.3 py-amqp:2.3.2
platform -> system:Linux arch:64bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:redis://redis/0

broker_url: 'amqp://user:********@rabbitmq:5672/test'
result_backend: 'redis://redis/0'

Steps to reproduce

When trying to create workflows which are started within a task like this:

#app.py
@app.task
def add(x, y):
    return x + y


@app.task
def kickstart():
    test_chain = (
        add.s(1, 1) | 
        add.s(2) | 
        group(
            add.s(3),
            add.s(4)
        )
    )
    result = test_chain()
    return result

one cannot build a graph out of the result of the kickstart task:

>>> import app
>>> res = app.kickstart.delay()
>>> res.graph

A TypeError: unhashable type: 'GroupResult' is raised

Expected behavior

A graph should be constructed.

Actual behavior

A TypeError: unhashable type: 'GroupResult' is raised:

KeyError                                  Traceback (most recent call last)
~/.local/share/virtualenvs/project-cdmlHYK5/lib/python3.6/site-packages/kombu/utils/objects.py in __get__(self, obj, type)
     41         try:
---> 42             return obj.__dict__[self.__name__]
     43         except KeyError:

KeyError: 'graph'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-3-dd95ac617ced> in <module>()
----> 1 res.graph

~/.local/share/virtualenvs/project-cdmlHYK5/lib/python3.6/site-packages/kombu/utils/objects.py in __get__(self, obj, type)
     42             return obj.__dict__[self.__name__]
     43         except KeyError:
---> 44             value = obj.__dict__[self.__name__] = self.__get(obj)
     45             return value
     46 

/src/celery/result.py in graph(self)
    387     @cached_property
    388     def graph(self):
--> 389         return self.build_graph()
    390 
    391     @property

/src/celery/result.py in build_graph(self, intermediate, formatter)
    342         )
    343         for parent, node in self.iterdeps(intermediate=intermediate):
--> 344             graph.add_arc(node)
    345             if parent:
    346                 graph.add_edge(parent, node)

/src/celery/utils/graph.py in add_arc(self, obj)
     54     def add_arc(self, obj):
     55         """Add an object to the graph."""
---> 56         self.adjacent.setdefault(obj, [])
     57 
     58     def add_edge(self, A, B):

TypeError: unhashable type: 'GroupResult'```

I believe this is because the class `GroupResult` does not implements a `__hash__` method like the `AsyncResult` class: https://github.com/celery/celery/blob/master/celery/result.py#L353
We should probably implement `__hash__` and `__str__`.

Activity

  1. self-assigned this
    on Jun 2, 2018
  2. xirdneh commented on Jun 2, 2018

    @xirdneh
    MemberAuthor

    Writing tests for this.

  3. georgepsarakis commented on Jun 2, 2018

    @georgepsarakis
    Contributor

    @xirdneh possible duplicate of #4739 , there are some notes there which you can hopefully find useful.

  4. xirdneh commented on Jun 2, 2018

    @xirdneh
    MemberAuthor

    Yes, it is a duplicate.
    Your notes on #4739 are a better solution since that way the graph will contain every node on the group result instead of just one node representing the group result.
    I'll take #4739 and submit a PR.
    Thanks.

  5. georgepsarakis commented on Jun 2, 2018

    @georgepsarakis
    Contributor

    Glad if I helped @xirdneh 😄

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions