Skip to content

Commit

Permalink
Ensure that 'total_rows' returned from 'Table.fetch_data' is an integer.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed May 27, 2016
1 parent 1ad4613 commit 03218dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gcloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ def fetch_data(self, max_results=None, page_token=None, client=None):
path='%s/data' % self.path,
query_params=params)
total_rows = response.get('totalRows')
if total_rows is not None:
total_rows = int(total_rows)
page_token = response.get('pageToken')
rows_data = _rows_from_json(response.get('rows', ()), self._schema)

Expand Down
6 changes: 2 additions & 4 deletions gcloud/bigquery/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def _bigquery_timestamp_float_repr(ts_float):
return '%0.15E' % (ts_float,)

DATA = {
'totalRows': ROWS,
'totalRows': str(ROWS),
'pageToken': TOKEN,
'rows': [
{'f': [
Expand Down Expand Up @@ -987,10 +987,8 @@ def test_fetch_data_w_alternate_client(self):
PATH = 'projects/%s/datasets/%s/tables/%s/data' % (
self.PROJECT, self.DS_NAME, self.TABLE_NAME)
MAX = 10
ROWS = 1234
TOKEN = 'TOKEN'
DATA = {
'totalRows': ROWS,
'rows': [
{'f': [
{'v': 'Phred Phlyntstone'},
Expand Down Expand Up @@ -1039,7 +1037,7 @@ def test_fetch_data_w_alternate_client(self):
self.assertEqual(rows[1], ('Bharney Rhubble', 33, False, 1.414))
self.assertEqual(rows[2], ('Wylma Phlyntstone', 29, True, 2.71828))
self.assertEqual(rows[3], ('Bhettye Rhubble', 27, None, None))
self.assertEqual(total_rows, ROWS)
self.assertEqual(total_rows, None)
self.assertEqual(page_token, None)

self.assertEqual(len(conn1._requested), 0)
Expand Down

0 comments on commit 03218dd

Please sign in to comment.