From 28a288924f4f714d5543f20b6d2e8f5e6c8dcf7f Mon Sep 17 00:00:00 2001 From: Danny Weinberg Date: Thu, 4 Jun 2020 16:20:32 -0700 Subject: [PATCH] Change to have `parse` *always* set serialized_on_wire --- betterproto/__init__.py | 6 +++--- betterproto/tests/test_features.py | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/betterproto/__init__.py b/betterproto/__init__.py index c728a7c..e9f2190 100644 --- a/betterproto/__init__.py +++ b/betterproto/__init__.py @@ -741,15 +741,15 @@ class Message(ABC): Parse the binary encoded Protobuf into this message instance. This returns the instance itself and is therefore assignable and chainable. """ + # Got some data over the wire + self._serialized_on_wire = True + for parsed in parse_fields(data): field_name = self._betterproto.field_name_by_number.get(parsed.number) if not field_name: self._unknown_fields += parsed.raw continue - # Got some data over the wire - self._serialized_on_wire = True - meta = self._betterproto.meta_by_field_name[field_name] value: Any diff --git a/betterproto/tests/test_features.py b/betterproto/tests/test_features.py index d714caf..024ab08 100644 --- a/betterproto/tests/test_features.py +++ b/betterproto/tests/test_features.py @@ -39,11 +39,9 @@ def test_has_field(): 2, betterproto.TYPE_STRING, betterproto.TYPE_STRING ) - # Unset with empty collections + # Is always set from parse, even if all collections are empty with_collections_empty = WithCollections().parse(bytes(WithCollections())) - assert betterproto.serialized_on_wire(with_collections_empty) == False - - # Set with non-empty collections + assert betterproto.serialized_on_wire(with_collections_empty) == True with_collections_list = WithCollections().parse( bytes(WithCollections(test_list=["a", "b", "c"])) )