Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chalmerlowe authored Jan 11, 2024
2 parents 22256f6 + 08483fb commit 506afa4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
[1]: https://pypi.org/project/google-cloud-bigquery/#history


## [3.15.0](https://github.com/googleapis/python-bigquery/compare/v3.14.1...v3.15.0) (2024-01-09)


### Features

* Support JSON type in `insert_rows` and as a scalar query parameter ([#1757](https://github.com/googleapis/python-bigquery/issues/1757)) ([02a7d12](https://github.com/googleapis/python-bigquery/commit/02a7d129776b7da7da844ffa9c5cdf21811cd3af))
* Support RANGE in schema ([#1746](https://github.com/googleapis/python-bigquery/issues/1746)) ([8585747](https://github.com/googleapis/python-bigquery/commit/8585747058e6db49a8078ae44d8e10735cdc27f9))


### Bug Fixes

* Deserializing JSON subfields within structs fails ([#1742](https://github.com/googleapis/python-bigquery/issues/1742)) ([0d93073](https://github.com/googleapis/python-bigquery/commit/0d930739c78b557db6cd48b38fe16eba93719c40))
* Due to upstream change in dataset, updates expected results ([#1761](https://github.com/googleapis/python-bigquery/issues/1761)) ([132c14b](https://github.com/googleapis/python-bigquery/commit/132c14bbddfb61ea8bc408bef5e958e21b5b819c))
* Load_table_from_dataframe for higher scale decimal ([#1703](https://github.com/googleapis/python-bigquery/issues/1703)) ([b9c8be0](https://github.com/googleapis/python-bigquery/commit/b9c8be0982c76187444300c414e0dda8b0ad105b))
* Updates types-protobuf version for mypy-samples nox session ([#1764](https://github.com/googleapis/python-bigquery/issues/1764)) ([c0de695](https://github.com/googleapis/python-bigquery/commit/c0de6958e5761ad6ff532dd933b0f4387e18f1b9))


### Performance Improvements

* DB-API uses more efficient `query_and_wait` when no job ID is provided ([#1747](https://github.com/googleapis/python-bigquery/issues/1747)) ([d225a94](https://github.com/googleapis/python-bigquery/commit/d225a94e718a85877c495fbd32eca607b8919ac6))

## [3.14.1](https://github.com/googleapis/python-bigquery/compare/v3.14.0...v3.14.1) (2023-12-13)


Expand Down
25 changes: 22 additions & 3 deletions google/cloud/bigquery/job/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}


def _error_result_to_exception(error_result):
def _error_result_to_exception(error_result, errors=None):
"""Maps BigQuery error reasons to an exception.
The reasons and their matching HTTP status codes are documented on
Expand All @@ -66,6 +66,7 @@ def _error_result_to_exception(error_result):
Args:
error_result (Mapping[str, str]): The error result from BigQuery.
errors (Union[Iterable[str], None]): The detailed error messages.
Returns:
google.cloud.exceptions.GoogleAPICallError: The mapped exception.
Expand All @@ -74,8 +75,24 @@ def _error_result_to_exception(error_result):
status_code = _ERROR_REASON_TO_EXCEPTION.get(
reason, http.client.INTERNAL_SERVER_ERROR
)
# Manually create error message to preserve both error_result and errors.
# Can be removed once b/310544564 and b/318889899 are resolved.
concatenated_errors = ""
if errors:
concatenated_errors = "; "
for err in errors:
concatenated_errors += ", ".join(
[f"{key}: {value}" for key, value in err.items()]
)
concatenated_errors += "; "

# strips off the last unneeded semicolon and space
concatenated_errors = concatenated_errors[:-2]

error_message = error_result.get("message", "") + concatenated_errors

return exceptions.from_http_status(
status_code, error_result.get("message", ""), errors=[error_result]
status_code, error_message, errors=[error_result]
)


Expand Down Expand Up @@ -886,7 +903,9 @@ def _set_future_result(self):
return

if self.error_result is not None:
exception = _error_result_to_exception(self.error_result)
exception = _error_result_to_exception(
self.error_result, self.errors or ()
)
self.set_exception(exception)
else:
self.set_result(self)
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigquery/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "3.14.1"
__version__ = "3.15.0"
21 changes: 21 additions & 0 deletions tests/unit/job/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ def test_missing_reason(self):
exception = self._call_fut(error_result)
self.assertEqual(exception.code, http.client.INTERNAL_SERVER_ERROR)

def test_contatenate_errors(self):
# Added test for b/310544564 and b/318889899.
# Ensures that error messages from both error_result and errors are
# present in the exception raised.

error_result = {
"reason": "invalid1",
"message": "error message 1",
}
errors = [
{"reason": "invalid2", "message": "error message 2"},
{"reason": "invalid3", "message": "error message 3"},
]

exception = self._call_fut(error_result, errors)
self.assertEqual(
exception.message,
"error message 1; reason: invalid2, message: error message 2; "
"reason: invalid3, message: error message 3",
)


class Test_JobReference(unittest.TestCase):
JOB_ID = "job-id"
Expand Down

0 comments on commit 506afa4

Please sign in to comment.