From e469059d70bab4c2b0a38dd52c4451b3c61bf470 Mon Sep 17 00:00:00 2001 From: Gabriele Date: Mon, 2 May 2022 12:04:46 +0200 Subject: [PATCH] fix: lookup attribute instead of performing a deepcopy (#226) * fix: lookup attribute instead of performing a deepcopy * address review feedback Co-authored-by: Anthonios Partheniou --- proto/marshal/collections/repeated.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/proto/marshal/collections/repeated.py b/proto/marshal/collections/repeated.py index 01b5d2fd..29bacff6 100644 --- a/proto/marshal/collections/repeated.py +++ b/proto/marshal/collections/repeated.py @@ -104,7 +104,13 @@ def _pb_type(self): if len(self.pb) > 0: return type(self.pb[0]) - # We have no members in the list. + # We have no members in the list, so we get the type from the attributes. + if hasattr(self.pb, "_message_descriptor") and hasattr( + self.pb._message_descriptor, "_concrete_class" + ): + return self.pb._message_descriptor._concrete_class + + # Fallback logic in case attributes are not available # In order to get the type, we create a throw-away copy and add a # blank member to it. canary = copy.deepcopy(self.pb).add()