-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to observe the AppendRowsResponse row_errors #836
Labels
api: bigquerystorage
Issues related to the googleapis/python-bigquery-storage API.
Comments
product-auto-label
bot
added
the
api: bigquerystorage
Issues related to the googleapis/python-bigquery-storage API.
label
Oct 11, 2024
Looks like a simple change is required: The base exception supports a response kwarg so I think we'd only need: future: AppendRowsFuture = self._futures_queue.get_nowait()
if response.error.code:
exc = exceptions.from_grpc_status(
response.error.code, response.error.message, response=response # <-- just add response here.
)
future.set_exception(exc)
else:
future.set_result(response) |
film42
added a commit
to film42/python-bigquery-storage
that referenced
this issue
Oct 11, 2024
Should an AppendRowsRequest fail, you need to inspect the response to see what went wrong. Currently this lib only raises an exception with the code and message, throwing the actual response away. This patch adds the response to any exception raise. This is fine because the base grpc error has a response kwarg that this lib wasn't using. Now you can catch the error and call `e.response.row_errors` to see the underlying row errors. Fixes: googleapis#836
4 tasks
Btw... for folks looking for a work-around while this is reviewed by google, I'm using this monkey patch at the moment. from google.protobuf import descriptor_pb2, descriptor_pool, message_factory
from google.cloud import bigquery_storage_v1
from google.cloud.bigquery_storage_v1 import types, writer
from google.api_core.exceptions import InvalidArgument
# HACK: I have to monkey patch AppendRowsStream until the following issue is closed
# and the response is accesssible from an append rows request exception.
#
# GH: https://github.com/googleapis/python-bigquery-storage/issues/836
#
def _monkey_patch_writer_append_rows_stream(w: writer.AppendRowsStream):
from google.api_core import exceptions
from google.cloud.bigquery_storage_v1 import exceptions as bqstorage_exceptions
# Take from my patch here: https://github.com/googleapis/python-bigquery-storage/pull/838
def _on_response(self, response: types.AppendRowsResponse):
"""Process a response from a consumer callback."""
# If the stream has closed, but somehow we still got a response message
# back, discard it. The response futures queue has been drained, with
# an exception reported.
if self._closed:
raise bqstorage_exceptions.StreamClosedError(
f"Stream closed before receiving response: {response}"
)
# Since we have 1 response per request, if we get here from a response
# callback, the queue should never be empty.
future: writer.AppendRowsFuture = self._futures_queue.get_nowait()
if response.error.code:
exc = exceptions.from_grpc_status(
response.error.code, response.error.message, response=response
)
future.set_exception(exc)
else:
future.set_result(response)
w._on_response = _on_response.__get__(w, type(w))
# ...
# Later on while make a new append row stream...
append_rows_stream = writer.AppendRowsStream(write_client, request_template)
# Apply monkey patch to instance.
_monkey_patch_writer_append_rows_stream(append_rows_stream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
If you are still having issues, please be sure to include as much information as possible:
Environment details
python --version
pip --version
google-cloud-bigquery-storage
version:pip show google-cloud-bigquery-storage
Steps to reproduce
'2024-10-11T00:17:35.479490+00:00'
.Please see previous issue #717 where @bhavitsharma ran into the same issue as I did.
Code example
Docs here say that errors must be read from the response which includes an index, msg, and error type for each row. https://cloud.google.com/bigquery/docs/reference/storage/rpc/google.cloud.bigquery.storage.v1#google.cloud.bigquery.storage.v1.AppendRowsResponse . But, there is no way to get access to the underlying response because on error this lib capture the code and message and throws away the rest:
python-bigquery-storage/google/cloud/bigquery_storage_v1/writer.py
Lines 285 to 292 in 4c87178
If you crack open the source code of this lib and modify it to print the
response.row_errors
you get:Stack trace
Without access to the response to inspect each row, this is the only thing you see:
400 Errors found while processing rows. Please refer to the row_errors field for details. The list may not be complete because of the size limitations. Entity: projects/my_project/datasets/my_dataset/tables/my_table/streams/my_stream_id
In other words... nothing helpful.
I think it would be great if we could have something like:
OR
The text was updated successfully, but these errors were encountered: