-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat: Add support for creating exceptions from an asynchronous response #688
Conversation
98d205f
to
573413a
Compare
google/api_core/exceptions.py
Outdated
return message | ||
|
||
|
||
def format_http_response_error(response, method, url, payload=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add type hints
nit: add code comments to clarify the reason that we're moving away from from_http_response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just minor comments/questions. Please address @parthea's comments as well.
@@ -32,6 +32,7 @@ def wrap_method( | |||
default_timeout=None, | |||
default_compression=None, | |||
client_info=client_info.DEFAULT_CLIENT_INFO, | |||
kind="grpc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, and when we call wrap_method
from the GAPIC, it will specify this parameter, right? So that will be in a follow-up PR in the generator repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct! Note to myself to update the default value to grpc_asyncio
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the PR description with the right default value.
Adding a |
…oogleapis/python-api-core into add-support-for-mapping-rest-callables
…oogleapis/python-api-core into add-support-for-mapping-rest-callables
Would this fix the issue in googleapis/gapic-generator-python#1764? Or is this something else? |
This PR removes grpc code path from the stack trace when an error is raised from an asynchronous rest call. |
This PR implements a_RestCall
class to mapGoogleAPICallError
to an asynchronous rest callable that raisesgoogle.auth.exceptions.TransportError
.This wrapping is done via a helper methodrest_helpers_async.wrap_errors
.A new parameter
kind
is introduced inwrap_method
which can be one ofgrpc_asyncio
(Default Value) orrest_asyncio
to distinguish between the type of callables so that we can apply the appropriate wrapping logic.The property kind is exposed at the transport level here and will be configured when wrapping methods during the transport initialization here.
As a follow up, a similar logic must be implemented for synchronous rest callables to avoid gRPC specific stack trace within a rest call.
RE: Updated Workflow:
I've removed the proposed
_RestCall
class after determining that it is not needed to wrap a rest callable and just adds unnecessary logic.The new proposed workflow is as follows:
kind
inwrap_method
to determine the type of a callable i.e.grpc_asyncio
orrest_asyncio
.kind=="rest_asyncio"
, we skip the call togrpc_helpers_async.wrap_errors
which is gRPC specific.Essentially, this does the trick if we follow a similar pattern for error handling to what we're doing in a sync rest call.
We have been lazily creating and raising a
GoogleAPICallError
from arequests.Response
within our GAPICs using the from_http_response method here. Therefore, we don't need to add the error handling logic to the callable beforehand (we're currently doing both the things for a sync rest call and should skip wrapping the callable beforehand there too).This PR only handles the error handling logic for an async REST call. It also introduces a new helper i.e.
format_http_response_error
to create and raise aGoogleAPICallError
for a more generic response since the existingfrom_http_response
is specific to handling arequests
response.Alternate approach for the introduced helper:
The proposed implementation of
format_http_response_error
takes in payload as an argument so that we don't need to await for it within the call and keep this function synchronous.Alternatively, we can have an async version of
from_http_response
that can be used to createGoogleAPICallError
for async rest calls.Follow Up:
As a follow up, we should skip wrapping sync rest callable with
grpc_helpers.wrap_errors
(similar to what we're doing here) to avoid the unnecessary gRPC specific logic within a rest call stracktrace.