Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit fb5f248

Browse files
committed
See protocolbuffers/protobuf#16596 breaking change
1 parent 4089092 commit fb5f248

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

proto/marshal/compat.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# not be included.
2020

2121
from google.protobuf.internal import containers
22+
import google.protobuf
23+
24+
PROTOBUF_VERSION = google.protobuf.__version__
2225

2326
# Import protobuf 4.xx first and fallback to earlier version
2427
# if not present.
@@ -36,15 +39,17 @@
3639
repeated_composite_types = (containers.RepeatedCompositeFieldContainer,)
3740
repeated_scalar_types = (containers.RepeatedScalarFieldContainer,)
3841
map_composite_types = (containers.MessageMap,)
42+
map_composite_types_str = ('MessageMapContainer')
3943

4044
if _message:
4145
repeated_composite_types += (_message.RepeatedCompositeContainer,)
4246
repeated_scalar_types += (_message.RepeatedScalarContainer,)
43-
map_composite_types += (_message.MessageMapContainer,)
44-
47+
if PROTOBUF_VERSION[0:2] in ["3.", "4."]:
48+
map_composite_types += (_message.MessageMapContainer,)
4549

4650
__all__ = (
4751
"repeated_composite_types",
4852
"repeated_scalar_types",
4953
"map_composite_types",
54+
"map_composite_types_str",
5055
)

proto/marshal/marshal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ def to_python(self, proto_type, value, *, absent: bool = None):
188188
return Repeated(value, marshal=self)
189189

190190
# Same thing for maps of messages.
191-
if value_type in compat.map_composite_types:
191+
# See https://github.com/protocolbuffers/protobuf/issues/16596
192+
# We need to look up the name of the type in compat.map_composite_types_str
193+
# as class `MessageMapContainer` is no longer exposed
194+
# This is done to avoid taking a breaking change in proto-plus
195+
if value_type in compat.map_composite_types or value_type.__name__ in compat.map_composite_types_str:
192196
return MapComposite(value, marshal=self)
193197
return self.get_rule(proto_type=proto_type).to_python(value, absent=absent)
194198

0 commit comments

Comments
 (0)