Skip to content

Commit

Permalink
fix: more should be boolean in fetch_page call (#423)
Browse files Browse the repository at this point in the history
* fix: more should be boolean in fetch_page call
refs #422
  • Loading branch information
cguardia authored May 13, 2020
1 parent cebf9f4 commit a69ffd2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion google/cloud/ndb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ def fetch_page_async(self, page_size, **kwargs):
results.append(result.entity())
cursor = result.cursor

more = results and (
more = bool(results) and (
iterator._more_results_after_limit or iterator.probably_has_next()
)
raise tasklets.Return(results, cursor, more)
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,36 @@ def has_next_async(self):
raw=True,
)

@staticmethod
@pytest.mark.usefixtures("in_context")
@mock.patch("google.cloud.ndb._datastore_query")
def test_fetch_page_no_results(_datastore_query):
class DummyQueryIterator:
_more_results_after_limit = True

def __init__(self):
self.items = []

def has_next_async(self):
return utils.future_result(bool(self.items))

_datastore_query.iterate.return_value = DummyQueryIterator()
query = query_module.Query()
query.filters = mock.Mock(
_multiquery=False, _post_filters=mock.Mock(return_value=False),
)
results, cursor, more = query.fetch_page(5)
assert results == []
assert cursor is None
assert more is False

_datastore_query.iterate.assert_called_once_with(
query_module.QueryOptions(
filters=query.filters, project="testing", limit=5
),
raw=True,
)

@staticmethod
@pytest.mark.usefixtures("in_context")
@mock.patch("google.cloud.ndb._datastore_query")
Expand Down

0 comments on commit a69ffd2

Please sign in to comment.