Skip to content
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

Update wrap_methods to optionally call wrap_errors if it is a gRPC callable #661

Open
ohmayr opened this issue May 24, 2024 · 0 comments
Open
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@ohmayr
Copy link
Contributor

ohmayr commented May 24, 2024

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)
@ohmayr ohmayr changed the title Update wrap_methods to optionally call wrap_errors if the it is a gRPC callable Update wrap_methods to optionally call wrap_errors if it is a gRPC callable May 24, 2024
@ohmayr ohmayr added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant