This is an automated email from the ASF dual-hosted git repository.
andreac pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/master by this push:
new 7e2451bdea Add __.V() wrapping for Vertex objects in to() and from()
methods (#3281)
7e2451bdea is described below
commit 7e2451bdeade46b2deb44d115f4150999669a35c
Author: kirill-stepanishin <[email protected]>
AuthorDate: Fri Nov 21 12:35:44 2025 -0800
Add __.V() wrapping for Vertex objects in to() and from() methods (#3281)
Fixes edge creation in gremlin-python by automatically wrapping Vertex
objects with __.V(vertex.id) in to() and from_() methods.
Key Changes:
• Wrap Vertex objects with __.V() in to() and from_() steps using
isinstance() check
• Pass through strings and traversals unchanged
• Update test expectations to verify Vertex wrapping functionality
• Revert manual __.V() wrapping from basic examples now that driver handles
it automatically
Relates to https://github.com/apache/tinkerpop/pull/3252
---
CHANGELOG.asciidoc | 1 +
gremlin-python/src/main/python/examples/basic_gremlin.py | 4 ++--
.../src/main/python/gremlin_python/process/graph_traversal.py | 11 +++++++++--
.../src/main/python/tests/process/test_traversal.py | 2 +-
4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 8df83871d4..c17785f245 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 873fd0a731..e2472b5714 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 2f6c20097c..2978a104fd 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 .traversal import GremlinLang
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 @@ class GraphTraversal(Traversal):
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 @@ class GraphTraversal(Traversal):
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 c52cbd4c39..52910fd210 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 @@ class TestTraversal(object):
# 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 = {