danielgtaylor / danielgtaylor/python-betterproto

Add a default values for rpc with empty message

Open
#613 1 comment 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

### 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:

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

To something like:
```python
answer = TestStub().call()
```

Contributor guide

Open the contributing guide

Research direction

No files or tests are identified in the issue. Start by locating the generated Python RPC method signatures and the current handling of google.protobuf.Empty or fieldless messages; done means empty-message RPCs can be called without an argument while existing explicit-message calls continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
grpc, python
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.