Open
Description
The following wrap_method
function is a common code path for both REST
and gRPC
which incorrectly tries to wrap errors for all callables via wrap_errors
but it's is meant to be used for only gRPC
callables:
def wrap_method(
func,
default_retry=None,
default_timeout=None,
default_compression=None,
client_info=client_info.DEFAULT_CLIENT_INFO,
):
func = grpc_helpers_async.wrap_errors(func)
metadata = [client_info.to_grpc_metadata()] if client_info is not None else None
return functools.wraps(func)(
_GapicCallable(
func,
default_retry,
default_timeout,
default_compression,
metadata=metadata,
)
)
Proposed fix:
try:
import grpc
from google.api_core import grpc_helpers_async
_STREAM_WRAP_CLASSES = (grpc.aio.UnaryUnaryMultiCallable, grpc.aio.UnaryStreamMultiCallable, grpc.aio.StreamUnaryMultiCallable, grpc.aio.StreamStreamMultiCallable)
except ImportError:
grpc = None
if grpc and isinstance(func, _STREAM_WRAP_CLASSES):
func = grpc_helpers_async.wrap_errors(func)