Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a9a213

Browse files
Discovery: Treat empty nextPageToken field the same as it not existing
Sending nextPageToken out with an empty string to Google's DFA API will raise a 500 error. This commit treats an empty nextPageToken field the same as it not existing at all so that method.list_next() will not attempt to retrieve a non-existent page of results.
1 parent dee9cd5 commit 2a9a213

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

googleapiclient/discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def methodNext(self, previous_request, previous_response):
857857
# Retrieve nextPageToken from previous_response
858858
# Use as pageToken in previous_request to create new request.
859859

860-
if 'nextPageToken' not in previous_response:
860+
if 'nextPageToken' not in previous_response or not previous_response['nextPageToken']:
861861
return None
862862

863863
request = copy.copy(previous_request)

tests/test_discovery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,14 @@ def test_next_successful_none_on_no_next_page_token(self):
11831183
request = tasks.tasklists().list()
11841184
self.assertEqual(None, tasks.tasklists().list_next(request, {}))
11851185

1186+
def test_next_successful_none_on_empty_page_token(self):
1187+
self.http = HttpMock(datafile('tasks.json'), {'status': '200'})
1188+
tasks = build('tasks', 'v1', http=self.http)
1189+
request = tasks.tasklists().list()
1190+
next_request = tasks.tasklists().list_next(
1191+
request, {'nextPageToken': ''})
1192+
self.assertEqual(None, next_request)
1193+
11861194
def test_next_successful_with_next_page_token(self):
11871195
self.http = HttpMock(datafile('tasks.json'), {'status': '200'})
11881196
tasks = build('tasks', 'v1', http=self.http)

0 commit comments

Comments
 (0)