]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
config: serialize dataclass instances in our JSONEncoder
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 29 Sep 2025 08:55:12 +0000 (10:55 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 2 Oct 2025 13:14:52 +0000 (15:14 +0200)
During config parsing we have partial dictionaries of our config, that are not
our Config object, but that we need to serialize as well. These may contain
dataclass instances such as ConfigTree objects on which the default encoder
chokes.

Fixes: #3924
mkosi/config.py

index f97055019a8970ffc017d7444413692c12523535..5ec6bac1028aab8c676d0f19cc8002aa99a3fa79 100644 (file)
@@ -5786,6 +5786,8 @@ class JsonEncoder(json.JSONEncoder):
             return str(o)
         elif isinstance(o, (Args, Config)):
             return o.to_dict()
+        elif dataclasses.is_dataclass(o) and not isinstance(o, type):
+            return dataclasses.asdict(o)
         return super().default(o)