Skip to content

Remove GenericArgument from from() and to()#3252

Merged
Cole-Greer merged 8 commits into
3.8-devfrom
from-to-id-fix
Oct 29, 2025
Merged

Remove GenericArgument from from() and to()#3252
Cole-Greer merged 8 commits into
3.8-devfrom
from-to-id-fix

Conversation

@Cole-Greer

@Cole-Greer Cole-Greer commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

from() and to() will now only accept Strings (alias for __.select()) and Traversals. If users wish to pass a vertex id, they may embed it in __.V() or __.constant().

The primary motivation here is to ensure consistent behaviour accross providers regardless of if their id types are numerics, strings, or other.

This PR is really a followup to an unintended consequence stemming from #3133. The issue with directly allowing ID's to be passed into from/to, it creates a weird asymmetry for graphs which use Strings as their ids. For example g.addE().from(1).to(2) would work fine and create an edge from V[1] to V[2], however if the graph used String ids, the equivalent traversal (g.addE().from("a").to("b")) does not work, as the Strings are interpreted as path labels (converted to __.select("a")) instead of vertex ids. There are some ugly workarounds which can partially mitigate this issue, but overall there is no generalized fix which allows all traversals to behave the same regardless of the vertex id type.

@Cole-Greer Cole-Greer marked this pull request as ready for review October 28, 2025 21:35
@Cole-Greer

Copy link
Copy Markdown
Contributor Author

VOTE +1

Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
@xiazcy

xiazcy commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

VOTE +1

Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
Comment on lines 772 to 774
gremlin> String.format("g.addE('knows').from(__.V(%s)).to(__.constant(%s))", v1.id(), v6.id())
==>g.addE('knows').from(__.V(1)).to(__.constant(6))
gremlin> client.submit(script).all().get().get(0).getEdge()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands do not work when executed in the console

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those examples are assuming a pre-existing client to submit remote scripts to a server. It's not really intended to be executable, the purpose is more to demonstrate how to properly pass from() and to() arguments in a script instead of embedding a ReferenceVertex.

And the traversal of
"""
g.addE("knows").from(vid1).to(vid6).property("weight", xx1)
g.addE("knows").from(V(vid1)).to(V(vid6)).property("weight", xx1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario names for the 2 modified tests should be updated (they seem out of date even prior to these changes).

And the traversal of
"""
g.addE(xx1).from(vid1).to(vid6).property("weight", xx2)
g.addE(xx1).from(V(vid1)).to(V(vid6)).property("weight", xx2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to change one of the tests to use constant instead of V.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately use of constant() here doesn't quite work as must be passed in as query parameters (to support providers with differing ID management systems), and constant does not take parameters. I will leave this test using V().

@kenhuuu

kenhuuu commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Nit: missing CHANGELOG

@kenhuuu

kenhuuu commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

I don't understand the need for this PR still after reviewing it. Can you maybe expand a bit about it in the documentation? What problem exactly is it trying to fix?

@Cole-Greer

Cole-Greer commented Oct 29, 2025

Copy link
Copy Markdown
Contributor Author

I don't understand the need for this PR still after reviewing it. Can you maybe expand a bit about it in the documentation? What problem exactly is it trying to fix?

This PR is really a followup to an unintended consequence stemming from #3133. The issue with directly allowing ID's to be passed into from/to, it creates a weird asymmetry for graphs which use Strings as their ids. For example g.addE().from(1).to(2) would work fine and create an edge from V[1] to V[2], however if the graph used String ids, the equivalent traversal (g.addE().from("a").to("b")) does not work, as the Strings are interpreted as path labels (converted to __.select("a")) instead of vertex ids. There are some ugly workarounds which can partially mitigate this issue, but overall there is no generalized fix which allows all traversals to behave the same regardless of the vertex id type.

(Adding this to the PR description as well)

@Cole-Greer

Copy link
Copy Markdown
Contributor Author

Nit: missing CHANGELOG

I'm not considering a new changelog entry as necessary as this is really a refinement of a previous unreleased change in 3.8-dev.

Cole-Greer and others added 8 commits October 28, 2025 20:01
from() and to() will now only accept Strings (alias for __.select()) and Traversals.
If users wish to pass a vertex id, they may embed it in __.V() or __.constant().

The primary motivation here is to ensure consistent behaviour accross providers regardless
of if their id types are numerics, strings, or other.
Co-authored-by: andreachild <andrea.child@improving.com>
Co-authored-by: andreachild <andrea.child@improving.com>
@kenhuuu

kenhuuu commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

VOTE +1

@Cole-Greer Cole-Greer merged commit 0b2e77e into 3.8-dev Oct 29, 2025
66 of 68 checks passed
@Cole-Greer Cole-Greer deleted the from-to-id-fix branch October 29, 2025 04:48
andreachild pushed a commit that referenced this pull request Nov 21, 2025
)

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 #3252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants