Skip to content

Commit

Permalink
Preview "(No data)" for cursors that return nothing; fixes #856
Browse files Browse the repository at this point in the history
  • Loading branch information
technige committed Nov 16, 2020
1 parent 4b4d592 commit 26e4952
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions py2neo/database/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ def __init__(self, result, hydrant=None, entities=None):
self._closed = False

def __repr__(self):
return repr(self.preview(3))
preview = self.preview(3)
if preview:
return repr(preview)
else:
return "(No data)"

def __next__(self):
if self.forward():
Expand Down Expand Up @@ -493,11 +497,14 @@ def preview(self, limit=1):
v = self._result.protocol_version
records = []
keys = self._result.fields()
for values in self._result.peek_records(int(limit)):
if self._hydrant:
values = self._hydrant.hydrate(keys, values, entities=self._entities, version=v)
records.append(values)
return Table(records, keys)
if keys:
for values in self._result.peek_records(int(limit)):
if self._hydrant:
values = self._hydrant.hydrate(keys, values, entities=self._entities, version=v)
records.append(values)
return Table(records, keys)
else:
return None

def evaluate(self, field=0):
""" Return the value of the first field from the next record
Expand Down

0 comments on commit 26e4952

Please sign in to comment.