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

Add a default values for rpc with empty message #613

Open
AdrienVannson opened this issue Sep 10, 2024 · 1 comment
Open

Add a default values for rpc with empty message #613

AdrienVannson opened this issue Sep 10, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@AdrienVannson
Copy link
Contributor

AdrienVannson commented Sep 10, 2024

The Problem

Sometimes, it is needed to declare RPCs that take no parameter. However, it is not possible in gRPC. In such a situation, it is needed to either create an empty message type, or to use google.protobuf.Empty ( https://stackoverflow.com/questions/29687243/protobuf-rpc-service-method-without-parameters ).

However, this is not convenient for the final user: an empty message need to be created and passed to the method each time. It also makes it necessary to add potentially long imports.

The Ideal Solution

To make this easier, it would be better to add a default value for the parameter containing the request when it is possible. I see two possibilities:

  • Add the default value only for google.protobug.Empty
  • Add the default value for all the messages who have no field at all

I think the second solution would be better as it is common to define empty messages in such situations. I can make a PR if you agree, I already have a working version locally.

The Current Solution

Currently, it is necessary for the user to import by hand from betterproto.lib.std.google.protobuf import Empty or the custom message, which is not convenient.

The feature would turn:

from betterproto.lib.std.google.protobuf import Empty
answer = TestStub().call(Empty())

To something like:

answer = TestStub().call()
@AdrienVannson AdrienVannson added the enhancement New feature or request label Sep 10, 2024
@Gobot1234
Copy link
Collaborator

Yeah I think this was the behaviour for v1.2.5 and I can agree it's helpful. Might be also useful to perform implicit returns for Empties as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants