Skip to content

Unable to build_graph() unhashable type: 'GroupResult' #4739

Closed

Description

@faffi

Version: celery==4.1.0

$ celery -A poc worker --loglevel=info
 
 -------------- [email protected] v4.1.0 (latentcall)
---- **** ----- 
--- * ***  * -- Darwin-16.7.0-x86_64-i386-64bit 2018-05-16 17:42:08
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         poc:0x10287fc18
- ** ---------- .> transport:   redis://localhost:6379/0
- ** ---------- .> results:     redis://localhost:6379/0
- *** --- * --- .> concurrency: 12 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . poc.add

Celery worker runs fine, issue seems to be when the graph is built with build_graph().

Traceback (most recent call last):
  File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
    return obj.__dict__[self.__name__]
KeyError: 'graph'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "poc.py", line 33, in <module>
    root.graph.to_dot(fh)
  File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/kombu/utils/objects.py", line 44, in __get__
    value = obj.__dict__[self.__name__] = self.__get(obj)
  File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/celery/result.py", line 354, in graph
    return self.build_graph()
  File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/celery/result.py", line 314, in build_graph
    graph.add_arc(node)
  File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/celery/utils/graph.py", line 53, in add_arc
    self.adjacent.setdefault(obj, [])
TypeError: unhashable type: 'GroupResult'

Steps to reproduce

import celery
from celery.canvas import group, chain

app = celery.Celery('poc')

app.conf.update(
	task_serializer='json',
	accept_content=['json'], 
	result_serializer='json',
	enable_utc=True,
	broker_url = 'redis://localhost:6379/0',
	result_backend = 'redis://localhost:6379/0'
)

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

if __name__ == '__main__':

	res = chain(add.si(1,1), group(add.si(2,2), add.si(3,3), add.si(4,4)))()
	res.get()

	# Find root result of graph
	root = res.parent
	while root.parent is not None:
		root = root.parent

	with open('graph.dot', 'w') as fh:
		root.graph.to_dot(fh)

Expected behavior

Generate the dotfile as expected by transforming each list item task id into a node entity with a corresponding arc for the graph.

Actual behavior

Error shown above.

Disclaimer: I am brand new to celery.

Activity

  1. changed the title [-]Unable to generate dotfile: to_dot() unhashable type: 'GroupResult'[/-] [+]Unable to build_graph() unhashable type: 'GroupResult'[/+] on May 17, 2018
  2. auvipy commented on May 22, 2018

    @auvipy
    Member

    does celery 4.2rc4 remove this error?

  3. faffi commented on May 22, 2018

    @faffi
    Author

    Hi auvipy,

    4.2rc4 does not remove the error. Snippets below.

    $ celery -A poc worker --loglevel=info
     
     -------------- [email protected] v4.2.0rc4 (windowlicker)
    ---- **** ----- 
    --- * ***  * -- Darwin-16.7.0-x86_64-i386-64bit 2018-05-22 14:24:24
    -- * - **** --- 
    - ** ---------- [config]
    - ** ---------- .> app:         poc:0x10f3bf668
    - ** ---------- .> transport:   redis://localhost:6379/0
    - ** ---------- .> results:     redis://localhost:6379/0
    - *** --- * --- .> concurrency: 12 (prefork)
    -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
    --- ***** ----- 
     -------------- [queues]
                    .> celery           exchange=celery(direct) key=celery
                    
    
    [tasks]
      . poc.add
    
    
    Traceback (most recent call last):
      File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
        return obj.__dict__[self.__name__]
    KeyError: 'graph'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "poc.py", line 166, in <module>
        root.graph.to_dot(fh)
      File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/kombu/utils/objects.py", line 44, in __get__
        value = obj.__dict__[self.__name__] = self.__get(obj)
      File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/celery-4.2.0rc4-py3.6.egg/celery/result.py", line 389, in graph
        return self.build_graph()
      File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/celery-4.2.0rc4-py3.6.egg/celery/result.py", line 344, in build_graph
        graph.add_arc(node)
      File "/Users/user/.pyenv/versions/3.6.1/envs/3.6.1-celery-poc/lib/python3.6/site-packages/celery-4.2.0rc4-py3.6.egg/celery/utils/graph.py", line 56, in add_arc
        self.adjacent.setdefault(obj, [])
    TypeError: unhashable type: 'GroupResult'
    
  4. georgepsarakis commented on May 23, 2018

    @georgepsarakis
    Contributor

    @faffi I believe the error is caused because build_graph does not iterate over the results of a GroupResult. Perhaps the solution would be:

    if isinstance(node, AsyncResult):
        nodes = [node]
    elif isinstance(node, GroupResult):
        nodes = node
    else:
        raise Exception('unknown result type')
    for node in nodes:
        graph.add_arc(node)
        if parent:
            graph.add_edge(parent, node)
  5. self-assigned this
    on Jun 2, 2018
  6. xirdneh commented on Jun 2, 2018

    @xirdneh
    Member

    @georgepsarakis I think build_graph does loop through a ResultSet children.
    build_graph calls iterdeps which waits for each result to finish and if the result has any children it adds each children to the stack to be yield.
    The TypeError is raised when the graph tries to add a GroupResult as a node because GroupResult does not have a __hash__ method implemented.
    I added a __hash__ method and did a quick test and I can verify the graph is created correctly.

    Writing tests...

  7. added this to the v4.2 milestone on Jun 3, 2018
  8. thedrow commented on Jun 3, 2018

    @thedrow
    Contributor

    @xirdneh Good job.
    You marked this issue as Needs Testcase but a test case was provided.
    There is a label for Has Testcase.

  9. thedrow commented on Jun 3, 2018

    @thedrow
    Contributor

    Since this happened in Celery 4.1 I do not consider this a blocker for releasing 4.2.
    @xirdneh If you can fix it in the next couple of days, I'll merge it and we'll call it GA.
    If a fix is not provided, we'll release anyway.

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