Skip to content

Commit 182e5bd

Browse files
authored
Allow fetching more than the first page when max_results is set. (#3845)
* BigQuery: reproduce error fetching multiple results with DB-API. Add a system test to call `fetchall()` when multiple rows are expected. * BigQuery: system test to reproduce error of only fetching first page. This error applies to all BigQuery iterators, not just DB-API. * BigQuery: allow arraysize to be set after execute() It was allowed before, but it didn't result in the correct behavior. * max_results in BigQuery API had a different meaning from HTTPIterator. In BigQuery it means the page size, but the HTTPIterator it meant "don't fetch any more pages once you have these many rows." * Fix lint errors
1 parent f2aa180 commit 182e5bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/google-cloud-core/google/api/core/page_iterator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ class HTTPIterator(Iterator):
275275
signature takes the :class:`Iterator` that started the page,
276276
the :class:`Page` that was started and the dictionary containing
277277
the page response.
278+
next_token (str): The name of the field used in the response for page
279+
tokens.
278280
279281
.. autoattribute:: pages
280282
"""
@@ -283,13 +285,13 @@ class HTTPIterator(Iterator):
283285
_PAGE_TOKEN = 'pageToken'
284286
_MAX_RESULTS = 'maxResults'
285287
_NEXT_TOKEN = 'nextPageToken'
286-
_RESERVED_PARAMS = frozenset([_PAGE_TOKEN, _MAX_RESULTS])
288+
_RESERVED_PARAMS = frozenset([_PAGE_TOKEN])
287289
_HTTP_METHOD = 'GET'
288290

289291
def __init__(self, client, api_request, path, item_to_value,
290292
items_key=_DEFAULT_ITEMS_KEY,
291293
page_token=None, max_results=None, extra_params=None,
292-
page_start=_do_nothing_page_start):
294+
page_start=_do_nothing_page_start, next_token=_NEXT_TOKEN):
293295
super(HTTPIterator, self).__init__(
294296
client, item_to_value, page_token=page_token,
295297
max_results=max_results)
@@ -298,6 +300,7 @@ def __init__(self, client, api_request, path, item_to_value,
298300
self._items_key = items_key
299301
self.extra_params = extra_params
300302
self._page_start = page_start
303+
self._next_token = next_token
301304
# Verify inputs / provide defaults.
302305
if self.extra_params is None:
303306
self.extra_params = {}
@@ -327,7 +330,7 @@ def _next_page(self):
327330
items = response.get(self._items_key, ())
328331
page = Page(self, items, self._item_to_value)
329332
self._page_start(self, page, response)
330-
self.next_page_token = response.get(self._NEXT_TOKEN)
333+
self.next_page_token = response.get(self._next_token)
331334
return page
332335
else:
333336
return None

0 commit comments

Comments
 (0)