danielgtaylor / danielgtaylor/python-betterproto

Missing betterproto_lib_google_protobuf import if only used as rpc call parameter.

Open
#409 1 comment 1 reaction 0 assignees View on GitHub
compiler-bug
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

I'm using 2.0.0b5.

The following file results in broken python:

```proto
syntax = "proto3";

package experiment;

import "google/protobuf/empty.proto";

message Reply {
bool happy = 1;
}

service Testcase {
rpc call(google.protobuf.Empty) returns (Reply);
}
```

Specifically, the import `import betterproto.lib.google.protobuf as betterproto_lib_google_protobuf` is missing from the output file.

When any `google.protobuf` imported field is used anywhere else, it does work correctly, for example, the following files all work:

```proto
syntax = "proto3";

package experiment;

import "google/protobuf/empty.proto";

message Reply {
bool happy = 1;
}

service Testcase {
rpc call(Reply) returns (google.protobuf.Empty);
}
```

```proto
syntax = "proto3";

package experiment;

import "google/protobuf/empty.proto";

message Reply {
bool happy = 1;
google.protobuf.Empty e = 2;
}

service Testcase {
rpc call(google.protobuf.Empty) returns (Reply);
}

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided .proto input and inspect the generated Python output file. Compare the missing dependency import when Empty is used only as an RPC parameter with the working return and field cases; done when the generated module includes the required import and remains valid Python.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.