8000 fix: keep `RowIterator.total_rows` populated after iteration by tswast · Pull Request #1748 · googleapis/python-bigquery · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2997,9 +2997,9 @@ def _rows_page_start(iterator, page, response):
page._columns = _row_iterator_page_columns(iterator._schema, response)

total_rows = response.get("totalRows")
# Don't reset total_rows if it's not present in the next API response.
if total_rows is not None:
total_rows = int(total_rows)
iterator._total_rows = total_rows
iterator._total_rows = int(total_rows)


# pylint: enable=unused-argument
Expand Down
11 changes 9875 : 10 additions & 1 deletion tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2201,9 +2201,18 @@ def test_iterate_with_cached_first_page(self):
path = "/foo"
api_request = mock.Mock(return_value={"rows": rows})
row_iterator = self._make_one(
_mock_client(), api_request, path, schema, first_page_response=first_page
_mock_client(),
api_request,
path,
schema,
first_page_response=first_page,
total_rows=4,
)
self.assertEqual(row_iterator.total_rows, 4)
rows = list(row_iterator)
# Total rows should be maintained, even though subsequent API calls
# don't include it.
self.assertEqual(row_iterator.total_rows, 4)
self.assertEqual(len(rows), 4)
self.assertEqual(rows[0].age, 27)
self.assertEqual(rows[1].age, 28)
Expand Down
0