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:
@@ -1738,8 +1738,8 @@ cdef class _DynamicStructBuilder:
|
|||||||
def from_dict(self, dict d):
|
def from_dict(self, dict d):
|
||||||
for key, val in d.iteritems():
|
for key, val in d.iteritems():
|
||||||
if key != 'which':
|
if key != 'which':
|
||||||
field = self.schema.fields.get(key)
|
|
||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
|
field = self.schema.fields.get(key)
|
||||||
dtype = field.proto.slot.type.which()
|
dtype = field.proto.slot.type.which()
|
||||||
if dtype == "data":
|
if dtype == "data":
|
||||||
# decode bytes from utf-8 base64 encoding
|
# decode bytes from utf-8 base64 encoding
|
||||||
|
|||||||
Reference in New Issue
Block a user