0

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 .proto files.
  • 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.

2
  • Is this a theoretical question or are you looking for a workaround? Commented Jul 2 at 11:16
  • You have 2 choices: (1) Don't duplicate identical (Message) definitions; import shared definitions instead; (2) Deduplicate otherwise identical (Message) definitions by putting them into different packages. Commented Jul 2 at 21:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.