You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The script whould print request1 and request2 objects
What did you see instead?
/test/venv/lib/python3.12/site-packages/google/protobuf/runtime_version.py:112: UserWarning: Protobuf gencode version 5.28.1 is older than the runtime version 5.28.2 at My.ProtoV1.proto. Please avoid checked-in Protobuf gencode that can be obsolete.
warnings.warn(
/test/venv/lib/python3.12/site-packages/google/protobuf/runtime_version.py:112: UserWarning: Protobuf gencode version 5.28.1 is older than the runtime version 5.28.2 at My.ProtoV2.proto. Please avoid checked-in Protobuf gencode that can be obsolete.
warnings.warn(
Traceback (most recent call last):
File "/test/my_proto.py", line 10, in <module>
import My.ProtoV2_pb2 as V2
File "/test/My/ProtoV2_pb2.py", line 27, in <module>
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10My.ProtoV2.proto\",\n\tMyRequest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0e\n\x06userId\x18\x02 \x01(\t\")\n\nMyResponse\x12\x0f\n\x07pullIds\x18\x03 \x03(\x04J\x04\x08\x01\x10\x02J\x04\x08\x02\x10\x03\x62\x06proto3')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Couldn't build proto file into descriptor pool: duplicate symbol 'MyRequest'
Anything else we should know about your project / environment
I was expecting being able using both versions of MyProtoV1.proto and MyProtoV2.proto in the same script (to support different clients in my server).
Thank you!
The text was updated successfully, but these errors were encountered:
from My.ProtoV1_pb2 import MyRequest as MyRequestV1
from My.ProtoV2_pb2 import MyRequest as MyRequestV2
request1 = MyRequestV1()
request1.version = 1
request1.userId = "user1"
print("request1", request1)
request2 = MyRequestV2()
request2.version = 2
request2.userId = "user2"
print("request2", request2)
which results in the similar error:
File "/test/my_proto.py", line 10, in <module>
from My.ProtoV2_pb2 import MyRequest as MyRequestV2
File "/test/My/ProtoV2_pb2.py", line 27, in <module>
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10My.ProtoV2.proto\",\n\tMyRequest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0e\n\x06userId\x18\x02 \x01(\t\")\n\nMyResponse\x12\x0f\n\x07pullIds\x18\x03 \x03(\x04J\x04\x08\x01\x10\x02J\x04\x08\x02\x10\x03\x62\x06proto3')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Couldn't build proto file into descriptor pool: duplicate symbol 'MyRequest'
This is working as expected - both of the proto files you're importing attempt to define the same messages, which is an error.
Typically when evolving schema, changes are done in place so that you can continue serving clients that have the old schema and may not be aware of the latest changes.
Consider the following as the only proto you script imports:
Legacy clients will continue populating the original id and pull fields, while newer clients will populate pullIds instead.
You can also add the [deprecated = true] field option to the old fields. Protobuf Python may not do anything with that field option yet but may in the future, but consider adding it to id and pull now if you have Java or C++ clients.
If you absolutely have to have completely separate schema for each version, than you'll need avoid the name collisions by either changing the message name in one of the proto files, or separating them into distinct directories so that they have different package prefixes. See https://protobuf.dev/reference/python/python-generated/#package for more details.
What version of protobuf and what language are you using?
protoc 28.1
python 3.12.6
What operating system (Linux, Windows, ...) and version?
macOS 14.6.1
What runtime / compiler are you using (e.g., python version or gcc version)
I am not sure, sorry. I just use the protoc and python from the homebrew
What did you do?
MyProtoV1.proto:
MyProtoV2.proto:
my_proto.py:
Commands I run:
What did you expect to see
The script whould print request1 and request2 objects
What did you see instead?
Anything else we should know about your project / environment
I was expecting being able using both versions of MyProtoV1.proto and MyProtoV2.proto in the same script (to support different clients in my server).
Thank you!
The text was updated successfully, but these errors were encountered: