fix: skip schema lookup when value is not a str (#401)

Since 84674909 (#351, "added binary support in dictionaries via base64
encoding"), `_DynamicStructBuilder.from_dict` does a
`self.schema.fields.get(key)` lookup for every key in the input dict.
The lookup was added so that `str` values destined for a `Data` field
can be base64-decoded, but the lookup itself runs unconditionally, even
when the value is `bool`, `int`, `dict`, `list`, `bytes`, etc.
This commit is contained in:
Atsushi Abe
2026-05-31 03:59:21 +09:00
committed by GitHub
parent 76a41c8efe
commit a27c849021

View File

@@ -1738,8 +1738,8 @@ cdef class _DynamicStructBuilder:
def from_dict(self, dict d):
for key, val in d.iteritems():
if key != 'which':
field = self.schema.fields.get(key)
if isinstance(val, str):
field = self.schema.fields.get(key)
dtype = field.proto.slot.type.which()
if dtype == "data":
# decode bytes from utf-8 base64 encoding