[Bug] clone query affects original cloned query
[X] I am using the latest release (3.7.2)
I believe the clone function code in gremlin-javascript contains a bug:
Notes:
- I renamed
process
to gProcess
as it's a global variable in Nodejs
- The following code is written in Typescript
The example code outputs:
The count
step affects both first
and cloned
.
I may be using clone
wrong, but the behavior I'm looking for is cloning an existing query.
I have searched the source code and believe the clone
function is improperly implemented.
Commit it was added:
https://github.com/apache/tinkerpop/commit/e3960486459152c31565642f772a8df0c57ca9f6#diff-38672d19a01405e314993c9e06586f19ef66b0a89f7c9f34d17273848cef3c1dR208
Thank you in advance ๐Solution:Jump to solution
Hi @Jonathan Fridja, thanks for reporting the issue, I agree that this appears to be a bug. Unlike the clone() implementation in the java driver which this was based off of, the js clone only creates a shallow copy which does not clone the underlying bytecode.
For reference this is how clone is implemented in Java: https://github.com/apache/tinkerpop/blob/76190de1086d8be4e207e69d1cc599c9d036a8b5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java#L267-L290.
Would you be willing to submit a PR to the 3.6-dev with a fix to fix to create a deep copy of the bytecode? If you could, that would be great, otherwise I can open up a JIRA to track this bug....
GitHub
tinkerpop/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/p...
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
2 Replies
Solution
Hi @Jonathan Fridja, thanks for reporting the issue, I agree that this appears to be a bug. Unlike the clone() implementation in the java driver which this was based off of, the js clone only creates a shallow copy which does not clone the underlying bytecode.
For reference this is how clone is implemented in Java: https://github.com/apache/tinkerpop/blob/76190de1086d8be4e207e69d1cc599c9d036a8b5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java#L267-L290.
Would you be willing to submit a PR to the 3.6-dev with a fix to fix to create a deep copy of the bytecode? If you could, that would be great, otherwise I can open up a JIRA to track this bug.
GitHub
tinkerpop/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/p...
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
I'll draft it, should I add a link here after I do it? or maybe reference this post in the PR