Language / runtime: Python 3.12.3
Operating system: Linux (Ubuntu 24.04)
Protoc / protobuf versions:
- protoc (libprotoc) 31.0
- protobuf 6.30.1
- grpcio-tools 1.73.1
Description:
- My project has two independent
.protofiles. - Both files use the same package and repeat several message definitions, e.g.:
protobuf
// file: grpc_interface_1.proto
syntax = "proto3";
package core.grpc_interface;
message Message1 {
string id = 1;
}
// file: grpc_interface_2.proto
syntax = "proto3";
package core.grpc_interface;
message Message1 { // identical name
string id = 1;
}
- Each file is compiled to Python with:
python -m grpc_tools.protoc \
-I=. --python_out=. --grpc_python_out=. grpc_interface_1.proto
python -m grpc_tools.protoc \
-I=. --python_out=. --grpc_python_out=. grpc_interface_2.proto
- During a single pytest session the test code imports both generated files:
import grpc_interface_1_pb2 # works
import grpc_interface_2_pb2 # boom
- and raises
TypeError: Couldn't build proto file into descriptor pool:
duplicate symbol 'core.grpc_interface.Message1'
Question:
- How can I use two proto files that both define the same message?
Notes:
- I understand duplicate symbols are currently rejected by the global DescriptorPool, but I could not find an official statement in the documentation or release notes.
I tried using several command options, but none of them worked.
importshared definitions instead; (2) Deduplicate otherwise identical (Message) definitions by putting them into different packages.