From a27c8490210ea4b9a66166fea0807ae8c96c604e Mon Sep 17 00:00:00 2001 From: Atsushi Abe Date: Sun, 31 May 2026 03:59:21 +0900 Subject: [PATCH] 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. --- capnp/lib/capnp.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 2439f1a..a6eddb0 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -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