4

This below piece of gremlin code runs perfectly well in the gremlin console (it finds the unique start and end points of an k-step ego network, along with the minimum distance to that endpoint):

g.V(42062000).as("from")
    .repeat(both().as("to")).emit().times(3).path()
    .count(local).as("pathlen")
    .select("from", "to", "pathlen")
    .dedup("from", "to").toList()

And gives an output similar to the following, which is as expected:

==>{from=v[42062000], to=v[83607800], plen=2}
==>{from=v[42062000], to=v[23683248], plen=3}
==>{from=v[42062000], to=v[41762840], plen=3}
==>{from=v[42062000], to=v[42062000], plen=3}
==>{from=v[42062000], to=v[83599456], plen=3}

However, when converting the code to conform to the gremlinpython wrapper (i.e. after substituting as for as_), I'm given the error TypeError: Object of type GraphTraversal is not JSON serializable, even though it's the same query.

Has anyone faced similar issues?

I am using gremlinpython 3.4.2, but was originally using 3.3.3. My version of Python is 3.7.3.

Chris Papantonis
  • 720
  • 7
  • 18
Ian
  • 3,605
  • 4
  • 31
  • 66
  • 1
    I'm not sure if this is part of the problem but you should try to use the same version of gremlinpython as is being used on the server. So, if you're 3.3.3 on the server then stick to 3.3.3 on the client. You can typically mix match versions along the `z` of `x.y.z` without too much trouble but always check the upgrade notes to be sure. You less often mix the `y`, but it can sometimes cause issues which are usually mentioned in the upgrade notes. Not sure that this is your problem here though..... – stephen mallette Jul 20 '19 at 00:34

1 Answers1

1

import static classes using

from gremlin_python import statics

statics.load_statics(globals())

or

from gremlin_python.process.graph_traversal import elementMap, range_, 
  local, count

and common reserved words must end with _

Example:

as_, range_
Thirumal
  • 8,280
  • 11
  • 53
  • 103