danielgtaylor / danielgtaylor/python-betterproto

Missing import in generated code when using well known types

Open
#552 1 comment 4 reactions 0 assignees View on GitHub
bug investigation needed
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

### Summary

When compiling a proto file which references well known types, `protoc` should generate the line `import betterproto.lib.google.protobuf as betterproto_lib_google_protobuf`. This does not happen in the following edge case.

### Reproduction Steps

Create a file `foo.proto` whith the following content
```proto
syntax = "proto3";
import "google/protobuf/empty.proto";

service foo {
rpc foo (google.protobuf.Empty) returns (MyEmpty);
}

message MyEmpty {}
```
and compile it by running `python -m grpc_tools.protoc -I . --python_betterproto_out=lib foo.proto`.

### Expected Results

The generated file `__init__.py` references a module `betterproto_lib_google_protobuf`, so it should import `betterproto.lib.google.protobuf` as `betterproto_lib_google_protobuf`.

Note that it actually would be imported if I had used `google.protobuf.Empty` as the return value of the RPC above.

### Actual Results

The generated file `__init__.py` does not import `betterproto.lib.google.protobuf` as `betterproto_lib_google_protobuf`

### System Information

libprotoc 25.0
Python 3.10.12
betterproto 2.0.0b6 (tested with released version and github master branch)

### Checklist

- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with foo.proto and the stated python -m grpc_tools.protoc command, then inspect the generated __init__.py. Compare the output when google.protobuf.Empty is used as the RPC return value. Done means the edge-case output imports betterproto.lib.google.protobuf under the referenced alias and the generated code compiles successfully.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.