Gremlinpython and debug incompatibility

84 views
Skip to first unread message

csce...@gmail.com

unread,
Oct 4, 2020, 1:04:19 PM10/4/20
to Gremlin-users
Hey,

I've changed a couple of my queries and I just realized that I can't debug my code anymore. When the traversal is introspected by PyCharm it doesn't return anything anymore !
so if I don't step in the function that builds and traverses my traversal I get results, but if I do it in step by step hasNext() says there is nothing !

I've already noticed in the past that the traversal contains steps I never added and put it on debug mode but now it's a problem. Here is an example, in step by step of what is in the traversal before hasNext is called and says there is nothing 

[['V'], ['hasLabel', 'OID'], ['has', 'uuid', '90d68e71-aaaa-2bd1-ffff-06eab5232461'], ['has', 'email', 'email.com'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['as', 'v'], ['out'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['as', 'v'], ['select', <Pop.all_: 1>, 'v'], ['by', [['unfold'], ['valueMap', True], ['fold']]], ['values', '__len__'], ['values', '__len__'], ['values', '__len__'], ['values', '__len__']]

Executing it in a Python shell or evaluating the expression in PyCharm at the exact same time returns what is expected:

In [264]: g.V().hasLabel('OID').has('uuid', '90d68e71-aaaa-2bd1-ffff-06eab5232461').has('email', 'email.com').as_('v').out().as_('v').select(Pop.all_,'v').by(unfold().valueMap(True).fold()).toList()
Out[264]:
[[{<T.id: 1>: 1385,
   <T.label: 4>: 'OID',
   'v_created_at': [datetime.datetime(2020, 10, 4, 16, 38, 49)],
   'created_at': ['2019-01-01T12:13:14.100000'],
   'uuid': ['90d68e71-aaaa-2bd1-ffff-06eab5232461'],
   'email': ['email.com']},
  {<T.id: 1>: 1390,
   <T.label: 4>: 'UID',
   'twou_id': ['d63ec88c-c7e8-462f-ac73-dab9d31fafe9'],
   'v_created_at': [datetime.datetime(2020, 10, 4, 16, 38, 49)]}]]

I think gremlin python does something when the traversal gets introspected that prevents the query from getting results. It seems to happen in RemoteStrategy class when it calls https://github.com/apache/tinkerpop/blob/3.4.8/gremlin-python/src/main/jython/gremlin_python/driver/remote_connection.py#L149

--
Cyril

csce...@gmail.com

unread,
Oct 4, 2020, 1:18:58 PM10/4/20
to Gremlin-users
I was able to limit it to the following piece of code:

from gremlin_python.process.traversal import Pop
from gremlin_python.process.graph_traversal import unfold
props = [{'uuid': '90d68e71-aaaa-2bd1-ffff-06eab5232461', 'email': 'email.com'}]
traversal = g.V().hasLabel('OID')
graph_traversal = traversal.as_('v').out()
graph_traversal = graph_traversal.as_('v').select(Pop.all_,'v').by(unfold().valueMap(True).fold())
found = graph_traversal.hasNext()


found is True if the breakpoint is put after the call to hasNext()
found is False if it's put before the call to ....fold()
and if the breakpoint is put on the hasNext() as soon we try to run it the code breaks with a GremlinServerError 500 complaining that an ArrayList cannot be cast to org.apache.tinkerpop.gremlin.structure.Element 

Hope this helps

Stephen Mallette

unread,
Oct 5, 2020, 7:52:11 AM10/5/20
to gremli...@googlegroups.com
I assume the introspection must triggering the traversal to iterate so that it can see what is inside? That's not great from a debugging perspective but offhand I don't know what we would change to fix that. Debugging in Java has a similar issue depending on the context of what you are debugging. Thoughts?

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/d97a70e6-f9ba-414e-8f7c-969643f4ea45n%40googlegroups.com.

csce...@gmail.com

unread,
Oct 5, 2020, 3:31:11 PM10/5/20
to Gremlin-users
I would expect the traversal to iterate only through the use of specific function calls and not by iterating over it ? also calling the len function should not do anything to the traversal ? Yeah it's really bad to not be able to debug it ...

Stephen Mallette

unread,
Oct 6, 2020, 8:02:35 AM10/6/20
to gremli...@googlegroups.com
It looks like the problem is with PyCharm's approach to inspection:


Calling __len__ on inspection of a Traversal will trigger a call to gremlin-python sugar:


and that of course generates bytecode that will return nothing unless you happen to have a property key named "__len__" in your graph. Changing that implementation to:

    def __getattr__(self, key):
        if key == '__len__':
            raise AttributeError("nope")
        return self.values(key)

fixes the problem but I'm not sure that's the right fix offhand. I've created two issues as a result of this debugging:

https://issues.apache.org/jira/browse/TINKERPOP-2434 - i thought i saw strange toString() issues around bytecode but now i'm not so sure. will need to test further when i have time

If anyone has advice on how to best resolve this, I'm open to suggestions. Thanks!






csce...@gmail.com

unread,
Oct 6, 2020, 10:29:32 AM10/6/20
to Gremlin-users
Thank you !
Reply all
Reply to author
Forward
0 new messages