From 6c6849ceab8a4c7534af89959432972fe487bb29 Mon Sep 17 00:00:00 2001 From: Daniel Nouri Date: Wed, 14 Dec 2011 20:15:30 +0100 Subject: [PATCH] Allow use of 'None' as 'missing' for DateTimes. --- colander/__init__.py | 2 +- colander/tests/test_colander.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/colander/__init__.py b/colander/__init__.py index 6719450..284ebd0 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -1231,7 +1231,7 @@ class DateTime(SchemaType): self.default_tzinfo = default_tzinfo def serialize(self, node, appstruct): - if appstruct is null: + if not appstruct: return null if type(appstruct) is datetime.date: # cant use isinstance; dt subs date diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index 631cf8a..17e5a5b 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -1542,6 +1542,14 @@ class TestDateTime(unittest.TestCase): result = typ.serialize(node, val) self.assertEqual(result, colander.null) + def test_serialize_none(self): + import colander + val = None + node = DummySchemaNode(None) + typ = self._makeOne() + result = typ.serialize(node, val) + self.assertEqual(result, colander.null) + def test_serialize_with_garbage(self): typ = self._makeOne() node = DummySchemaNode(None)