I am trying to add edge to an existing node in gremlin-python. But graph traversal(g) object do not have addE method and vertex do not have addEdge method.
Asked
Active
Viewed 3,249 times
0
-
I know there are ways to do it like mentioned in this answer: https://stackoverflow.com/questions/40657636/how-to-remove-an-edge-and-add-a-new-edge-between-two-vertices but I want to do it like g.addE().from_(a).to(b).toList() – Bipul Karnani May 26 '17 at 11:27
1 Answers
2
You can do it with a mid-traversal V()
:
>>> vFrom = g.V(1).next()
>>> vTo = g.V(6).next()
>>> g.V(vTo).as_('t').V(vFrom).addE("knows").to("t").toList()
[e[13][1-knows->6]]
I did learn that there is a bug that prevents this approach that uses withSideEffect()
in TinkerPop 3.2.4:
>>> g.withSideEffect("t",vTo).V(vFrom).addE("knows").to("t").toList()
I created an issue to help track the bug.

stephen mallette
- 45,298
- 5
- 67
- 135
-
stephen: Thanks for the answer. Above answer given by you throws me following error: **TypeError: v[x] is not JSON serializable**. Can you please share your config which you are using for Gremlin or help me to change the config to solve this error. – Bipul Karnani May 29 '17 at 04:32
-
pypy version of `gremlinpython` is not updated which throws the above error. Hence I got the latest `gremlinpython` from github and installed it and it worked. Please update the package on pypy. – Bipul Karnani May 29 '17 at 13:36
-
I have gremlinpython 3.2.3 and it still throws the same error. When IO try it with gremlinpython3.3.0 nothing works. What might be the problem? – Arvind Nov 10 '17 at 08:05
-
According to the issue I created this issue was resolved in 3.2.6/3.3.0. Gremlin Python 3.3.0 should work with older versions of Gremlin Server given appropriate configuration, but I'd first confirm that you can get this working with 3.3.0 for both client and server. – stephen mallette Nov 10 '17 at 11:41
-
withSideEffect step faster than first method you mentioned about. can you explain why using withSideEffect step faster than V()? – Berkay Jun 30 '21 at 13:08
-