Racim Righi
Racim Righi

Reputation: 31

Spawning child traversals anonymously using Gremlin-python and graphexp

I'm trying to create a graph from scratch that i'm visualising in graphexp, but i'm struggling to undertand the anonymized traversals concept and how to create them

I'm using python 3.9 and gremlinpython 3.5.1

from gremlin_python.process.anonymous_traversal import traversal

self.g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin', 'g'))
statics.load_statics(globals())
def _add_vertex(self, name):
        return self.g.V().has('name', name).fold().coalesce(unfold(), addV().property('name',name)).next()
def _add_edge(self, v1, v2, weight, label):
        return self.g.V(v1).as_("fromVertex").V(v2).coalesce(inE(label).where(outV().as_(
            "fromVertex")), addE(label).property("weight", weight).from_("fromVertex")).next()

But i'm getting this error in graphexp when clicking on a vertex

Error retrieving data
The child traversal of [GraphStep(vertex,[696560]), PropertyMapStep(value)] was not spawned anonymously - use the __ class rather than a TraversalSource to construct the child traversal

The documentation is generally good but not very helpful for the anonymized traversals part. So how can I spawn anonymous child traversals using this method? and what does it really mean ?

Upvotes: 2

Views: 936

Answers (1)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

Starting with TinkerPop 3.5.x, using a g anywhere but at the start of a traversal will raise an error. It used to be possible to write something like:

g.V('1').addE('test').from(g.V('2'))

This actually can have some bad side effects, so in 3.5.x the parser now enforces that you must do one of:

g.V('1').addE('test').from(V('2'))

or

g.V('1').addE('test').from(__.V('2'))

That "double underscore" class __. is the so called anonymous traversal source. It is called that as it is not connected to a prior step by a dot, rather it is inside parens as a child traversal.

I would check your code to see if you are actually injecting a second g into your traversal.

Upvotes: 6

Related Questions