1
votes

I'm having great trouble adding properties to an edge using the gremlin_python wrapper.

I'm able to create the edge, as so:

eid1='123'
eid2='456'
edge = g.V().has('eid', eid1).addE('transaction').to(g.V().has('entity_id',eid2)).next()

But, adding properties to the edge doesn't work. As in: the code runs without error, but no changes occur on the edge itself, so when after I call g.E(edge).valueMap.toList(), it returns an empty list.

g.E(edge).property('foo','bar').iterate()    <-- I've also tried this without iterate.

It also doesn't work if I create the node and add a property on the same line of code.

The same code - but executed in the gremlin console - runs as expected. i.e., after creating the edge and assigning the property:

gremlin> g.E(edge).valueMap().toList()
==>{foo=bar}

Any help here would be greatly appreciated.


Update

I was unable to get this to work using the python wrapper on the graph traversal object, instead I ran the code through the client, which works as expected. But this is a workaround, and not a solution.

gremlin_client = client.Client('ws://localhost:8182/gremlin', 'g')

query = "g.V().has('eid', '123').addE('transaction').to(g.V().has('eid','456')).property('foo','bar').next()"
gremlin_client.submit(query).all().result()
2
can you explain what you mean by "doesn't execute"? do you get an error? or it just executes and no change to the database occurs? - stephen mallette
Hi Stephen, the latter, the code runs without error, but no change to the database occurs - Ian
Maybe the edits makes this more clear, thanks - Ian
hmm - could you try g.E(edge.id()).property(...)? - stephen mallette
No luck unfortunately. Using ...edge.id... works in the console, but fails in the same way as described via gremlin_python. - Ian

2 Answers

1
votes

I tested your scenario on 3.4.3-SNAPSHOT and don't see a problem:

>>> g.addV().property('entity_id','123').iterate()
[['addV'], ['property', 'entity_id', '123'], ['none']]
>>> g.addV().property('entity_id','456').iterate()
[['addV'], ['property', 'entity_id', '456'], ['none']]
>>> e = g.V().has('entity_id','123').addE('transaction').to(__.V().has('entity_id','456')).next()
>>> g.E(e).property('foo','bar').iterate()
[['E', e[4][0-transaction->2]], ['property', 'foo', 'bar'], ['none']]
>>> g.E(e).valueMap().toList()
[{u'foo': u'bar'}]

I do note that your example code does have a syntax error - looking at:

eid1='123'
eid2='456'
edge = g.V().has('eid', eid1).addE('transaction').to(g.V().has('entity_id',eid2)).next()

Specifically, you mix "eid" and "entity_id" as your vertex identifiers. Assuming "eid" is wrong and it should be "entity_id" I could see how this traversal would fail without update (as the initial vertex is never found) and then leave you in a position where you couldn't update the edge because it was never created.

In response to comments below I also tried this with including a property() update with TinkerGraph and did not experience problems:

>>> g.addV().property('entity_id','123').iterate()
[['addV'], ['property', 'entity_id', '123'], ['none']]
>>> g.V().toList()
[v[0]]
>>> g.addV().property('entity_id','456').iterate()
[['addV'], ['property', 'entity_id', '456'], ['none']]
>>> g.V().has('entity_id','123').addE('transaction').to(__.V().has('entity_id','456')).property('weight',0.1).property('time',1000000).iterate()
[['V'], ['has', 'entity_id', '123'], ['addE', 'transaction'], ['to', [['V'], ['has', 'entity_id', '456']]], ['property', 'weight', 0.1], ['property', 'time', 1000000], ['none']]
>>> g.E().valueMap().toList()
[{'time': 1000000, 'weight': 0.1}]

I'm really not sure what could be wrong.

1
votes

I fell into the same situation. Using edgeid.id['@value']['relationId'] worked for me.

g.E(edgeid.id['@value']['relationId']).property('foo','bar').iterate()

When we simply use g.E() in gremlin python it works but using edge to filter the edges is not supported in a way we expect. g.E(edge).toList() was empty. I figured it was not able to search the edges. So I used relationId directly and it worked.