1

When the expected vertex or edge is not present in the database, gremlin python raises the exception StopIteration. How to resolve/prevent the exception. Query to return none or empty instead of an error.

Eg:

g.V().hasLabel('employee').has('name', 'Thirumal').elementMap().next()

output when the vertex is not available

    def __next__(self):
    if self.traversers is None:
        self.traversal_strategies.apply_strategies(self)
    if self.last_traverser is None:
        self.last_traverser = next(self.traversers)
        StopIteration

  /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gremlin_python/process/traversal.py:50: StopIteration
Thirumal
  • 8,280
  • 11
  • 53
  • 103

1 Answers1

2

Instead of using next, use toList instead. Then, if there is no data, you will get back an empty list.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38