Skip to content

Commit 28a2889

Browse files
committed
Change to have parse *always* set serialized_on_wire
1 parent 5c70061 commit 28a2889

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

betterproto/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,15 +741,15 @@ def parse(self: T, data: bytes) -> T:
741741
Parse the binary encoded Protobuf into this message instance. This
742742
returns the instance itself and is therefore assignable and chainable.
743743
"""
744+
# Got some data over the wire
745+
self._serialized_on_wire = True
746+
744747
for parsed in parse_fields(data):
745748
field_name = self._betterproto.field_name_by_number.get(parsed.number)
746749
if not field_name:
747750
self._unknown_fields += parsed.raw
748751
continue
749752

750-
# Got some data over the wire
751-
self._serialized_on_wire = True
752-
753753
meta = self._betterproto.meta_by_field_name[field_name]
754754

755755
value: Any

betterproto/tests/test_features.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ class WithCollections(betterproto.Message):
3939
2, betterproto.TYPE_STRING, betterproto.TYPE_STRING
4040
)
4141

42-
# Unset with empty collections
42+
# Is always set from parse, even if all collections are empty
4343
with_collections_empty = WithCollections().parse(bytes(WithCollections()))
44-
assert betterproto.serialized_on_wire(with_collections_empty) == False
45-
46-
# Set with non-empty collections
44+
assert betterproto.serialized_on_wire(with_collections_empty) == True
4745
with_collections_list = WithCollections().parse(
4846
bytes(WithCollections(test_list=["a", "b", "c"]))
4947
)

0 commit comments

Comments
 (0)