From fe929a59f619d0d977d389269d43ca6766c01f1d Mon Sep 17 00:00:00 2001 From: Atsushi Abe Date: Fri, 15 May 2026 14:05:23 +0900 Subject: [PATCH] fix: skip schema lookup when value is not a str 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 2439f1a8a..a6eddb0f3 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