3
0
Fork 0

fix: serialize None to null, for ObjectRef schema type

not sure how this didn't come up until now..anyway hopefully it's the
right thing but we'll see
This commit is contained in:
Lance Edgar 2026-03-08 12:26:21 -05:00
parent 634c1b1fe5
commit 19cf6cf03a
2 changed files with 8 additions and 4 deletions

View file

@ -357,15 +357,17 @@ class ObjectRef(colander.SchemaType):
def serialize(self, node, appstruct): # pylint: disable=empty-docstring def serialize(self, node, appstruct): # pylint: disable=empty-docstring
""" """ """ """
# nb. normalize to empty option if no object ref, so that # normalize to empty option if no object ref, so that works as
# works as expected # expected
if self.empty_option and not appstruct: if self.empty_option and not appstruct:
return self.empty_option[0] return self.empty_option[0]
if appstruct is colander.null: # even if there is no empty option, still treat any false-ish
# value as null
if not appstruct:
return colander.null return colander.null
# nb. keep a ref to this for later use # keep a ref to this for later use
node.model_instance = appstruct node.model_instance = appstruct
# serialize to PK as string # serialize to PK as string

View file

@ -257,6 +257,8 @@ class TestObjectRef(DataTestCase):
typ = mod.ObjectRef(self.request) typ = mod.ObjectRef(self.request)
value = typ.serialize(node, colander.null) value = typ.serialize(node, colander.null)
self.assertIs(value, colander.null) self.assertIs(value, colander.null)
value = typ.serialize(node, None)
self.assertIs(value, colander.null)
# model instance # model instance
person = model.Person(full_name="Betty Boop") person = model.Person(full_name="Betty Boop")