You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/09/05 20:34:37 UTC
[2/2] tinkerpop git commit: TINKERPOP-1898 Fixed bug with python
lambdas and strategies
TINKERPOP-1898 Fixed bug with python lambdas and strategies
There is a bug in jython that prevents varargs from always being called correctly. Wrapping arguments in a collection seems to solve the problem - the test that demonstrated the problem is now working. CTR
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/c36fc5c6
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/c36fc5c6
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/c36fc5c6
Branch: refs/heads/tp32
Commit: c36fc5c6bd8be2ff05c73f895980ff75374fb0c4
Parents: 425bcd0
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Sep 5 16:15:13 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Sep 5 16:15:13 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/python/jsr223/PythonTranslator.java | 12 +++++++++++-
.../tests/driver/test_driver_remote_connection.py | 1 +
3 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36fc5c6/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index b175826..48f78e4 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* SSL security enhancements
* Fixed problem with Gremlin Server sometimes returning an additional message after a failure.
* Allowed spaces in classpath for `gremlin-server.bat`.
+* Fixed bug in traversals that used Python lambdas with strategies in `gremlin-python`.
* Modified Maven archetype for Gremlin Server to use remote traversals rather than scripts.
* Added an system error code for failed plugin installs for Gremlin Server `-i` option.
* Match numbers in `choose()` options using `NumberHelper` (match values, ignore data type).
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36fc5c6/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
index d8c73f0..521ef4f 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
@@ -125,10 +125,20 @@ public class PythonTranslator implements Translator.ScriptTranslator {
else {
traversalScript.append(".");
String temp = resolveSymbol(methodName) + "(";
+
+ // jython has trouble with java varargs...wrapping in collection seems to solve the problem
+ final boolean varargsBeware = instruction.getOperator().equals(TraversalSource.Symbols.withStrategies)
+ || instruction.getOperator().equals(TraversalSource.Symbols.withoutStrategies);
+ if (varargsBeware) temp = temp + "[";
+
for (final Object object : arguments) {
temp = temp + convertToString(object) + ",";
}
- traversalScript.append(temp.substring(0, temp.length() - 1)).append(")");
+ temp = temp.substring(0, temp.length() - 1);
+
+ if (varargsBeware) temp = temp + "]";
+
+ traversalScript.append(temp).append(")");
}
// clip off __.
if (this.importStatics && traversalScript.substring(0, 3).startsWith("__.")
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c36fc5c6/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index cd9101e..4d2409e 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -92,6 +92,7 @@ class TestDriverRemoteConnection(object):
assert 4 == g.V().count().next()
assert 0 == g.E().count().next()
assert 1 == g.V().label().dedup().count().next()
+ assert 4 == g.V().filter(lambda: ("lambda x: True", "gremlin-python")).count().next()
assert "person" == g.V().label().dedup().next()
#
g = Graph().traversal().withRemote(remote_connection). \