diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8df83871d4c..c17785f245b 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -82,6 +82,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Added `idleConnectionTimeout` setting for Gremlin Driver and automatic closing of idle connections * Enabled TCP Keep-Alive in GremlinServer. * Updated Python GLV examples to use HTTP and to run as part of the integration tests. +* Fixed `gremlin-python` `to()` and `from_()` methods to wrap Vertex objects with `__.V()` for proper edge creation. == TinkerPop 3.8.0 (Grix Greven) diff --git a/gremlin-python/src/main/python/examples/basic_gremlin.py b/gremlin-python/src/main/python/examples/basic_gremlin.py index 873fd0a731b..e2472b5714d 100644 --- a/gremlin-python/src/main/python/examples/basic_gremlin.py +++ b/gremlin-python/src/main/python/examples/basic_gremlin.py @@ -40,8 +40,8 @@ def main(): # be sure to use a terminating step like next() or iterate() so that the traversal "executes" # iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database) - g.V(v1).add_e('knows').to(__.V(v2)).property('weight', 0.75).iterate() - g.V(v1).add_e('knows').to(__.V(v3)).property('weight', 0.75).iterate() + g.V(v1).add_e('knows').to(v2).property('weight', 0.75).iterate() + g.V(v1).add_e('knows').to(v3).property('weight', 0.75).iterate() # retrieve the data from the "marko" vertex marko = g.V().has(VERTEX_LABEL, 'name', 'marko').values('name').next() diff --git a/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py index 2f6c20097c5..2978a104fd0 100644 --- a/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py +++ b/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py @@ -28,6 +28,7 @@ from ..driver.remote_connection import RemoteStrategy from .. import statics from ..statics import long +from ..structure.graph import Vertex log = logging.getLogger("gremlinpython") @@ -506,7 +507,10 @@ def format_(self, *args): return self def from_(self, *args): - self.gremlin_lang.add_step("from", *args) + if len(args) == 1 and isinstance(args[0], Vertex): + self.gremlin_lang.add_step("from", __.V(args[0].id)) + else: + self.gremlin_lang.add_step("from", *args) return self def group(self, *args): @@ -943,7 +947,10 @@ def times(self, *args): return self def to(self, *args): - self.gremlin_lang.add_step("to", *args) + if len(args) == 1 and isinstance(args[0], Vertex): + self.gremlin_lang.add_step("to", __.V(args[0].id)) + else: + self.gremlin_lang.add_step("to", *args) return self def toE(self, *args): diff --git a/gremlin-python/src/main/python/tests/process/test_traversal.py b/gremlin-python/src/main/python/tests/process/test_traversal.py index c52cbd4c39a..52910fd210b 100644 --- a/gremlin-python/src/main/python/tests/process/test_traversal.py +++ b/gremlin-python/src/main/python/tests/process/test_traversal.py @@ -370,7 +370,7 @@ def test_should_extract_id_from_vertex(self): # Test edge creation with from/to vertices from_to = g.add_e("Edge").from_(Vertex(1)).to(Vertex(2)) - assert "g.addE('Edge').from(1).to(2)" == from_to.gremlin_lang.get_gremlin() + assert "g.addE('Edge').from(__.V(1)).to(__.V(2))" == from_to.gremlin_lang.get_gremlin() # Test mergeE() with Vertex in dictionary merge_map = {