GeezerVison is showing github.com — fix: do not overwrite page_size with max_results when start_index is … · mirror-dump/python-bigquery@7d0fcee
File tree
Expand file treeCollapse file tree
Open diff view settings
google/cloud/bigquery/job
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: google/cloud/bigquery/job/query.py +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1532,8 +1532,9 @@ def result( # type: ignore # (incompatible with supertype) |
1532 | 1532 | # Setting max_results should be equivalent to setting page_size with |
1533 | 1533 | # regards to allowing the user to tune how many results to download |
1534 | 1534 | # while we wait for the query to finish. See internal issue: |
1535 | | - # 344008814. |
1536 | | - if page_size is None and max_results is not None: |
| 1535 | + # 344008814. But if start_index is set, user is trying to access a |
| 1536 | + # specific page, so we don't need to set page_size. See issue #1950. |
| 1537 | + if page_size is None and max_results is not None and start_index is None: |
1537 | 1538 | page_size = max_results |
1538 | 1539 |
|
1539 | 1540 | # When timeout has default sentinel value ``object()``, do not pass |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/unit/job/test_query.py +14-1Lines changed: 14 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1652,7 +1652,17 @@ def test_result_with_start_index(self): |
1652 | 1652 |
|
1653 | 1653 | start_index = 1 |
1654 | 1654 |
|
1655 | | - result = job.result(start_index=start_index) |
| 1655 | + # Verifies that page_size isn't overwritten by max_results when |
| 1656 | + # start_index is not None. See |
| 1657 | + # https://github.com/googleapis/python-bigquery/issues/1950 |
| 1658 | + page_size = 10 |
| 1659 | + max_results = 100 |
| 1660 | + |
| 1661 | + result = job.result( |
| 1662 | + page_size=page_size, |
| 1663 | + max_results=max_results, |
| 1664 | + start_index=start_index, |
| 1665 | + ) |
1656 | 1666 |
|
1657 | 1667 | self.assertIsInstance(result, RowIterator) |
1658 | 1668 | self.assertEqual(result.total_rows, 5) |
@@ -1665,6 +1675,9 @@ def test_result_with_start_index(self): |
1665 | 1675 | self.assertEqual( |
1666 | 1676 | tabledata_list_request[1]["query_params"]["startIndex"], start_index |
1667 | 1677 | ) |
| 1678 | + self.assertEqual( |
| 1679 | + tabledata_list_request[1]["query_params"]["maxResults"], page_size |
| 1680 | + ) |
1668 | 1681 |
|
1669 | 1682 | def test_result_error(self): |
1670 | 1683 | from google.cloud import exceptions |
|