gremlin python clone traversal

Viewed 286

I'm using gremlin-python to connect to gremlin-server and I'm trying to build up a query incrementally but I'm getting stuck. I have an initial part of my query like the following:

query = g.V().hasLabel('<some_label>')

Now I would like to do multiple things with this query, firstly I just want a count:

query.count().next()

Now if I do anything else using the query variable the count step is on the traversal, so something like the following doesn't work:

query.out('<some_edge_label>').valueMap().toList()

Looking at the docs it seems like I need to clone the traversal so I replaced the above with:

query = g.V().hasLabel('<some_label>')

count_query = query.clone()
count_query.count().next()

But query still has the count() step on it, when I print the bytecode even though I cloned it. Is this the expected behaviour for gremlin-python? Here is a complete example of what I'm talking about, printing the bytecode at each step:

query = g.V().hasLabel('alabel')
print(query)
q_count = query.clone()
print(q_count.count())
print(query)

[['V'], ['hasLabel', 'alabel']]
[['V'], ['hasLabel', 'alabel'], ['count']]
[['V'], ['hasLabel', 'alabel'], ['count']]

What do I do to clone/copy the start of the traversal so I can reuse it in gremlin-python?

2 Answers

It looks like this issue was a bug in gremlin-python and has been fixed in version 3.4.7. Updating the version solved my issue.

Related