From 15f2eab217bdd03eaedfe4493da9f12d5965c793 Mon Sep 17 00:00:00 2001 From: Jenny Danzmayr Date: Thu, 5 Dec 2024 03:22:27 +0100 Subject: [PATCH] fixed serialization of lazy attributes that evaluate to None Without this `None` is returned as the string 'None'. Needed by at least the I18nField --- src/c3nav/api/schema.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/c3nav/api/schema.py b/src/c3nav/api/schema.py index f54076b0..592525af 100644 --- a/src/c3nav/api/schema.py +++ b/src/c3nav/api/schema.py @@ -32,6 +32,12 @@ def make_serializable(values: Any): return type(values)(val.pk for val in values) return type(values)(make_serializable(val) for val in values) if isinstance(values, Promise): + # This is needed for lazy attributes that evaluate to `None` to be serialized properly. + # Without this `None` is returned as the string 'None'. + # It can't be `is None` as the left side is a Proxy and not actually `None`. + # Needed by at least the I18nField + if values == None: + return None return str(values) return values