diff --git a/CHANGES.txt b/CHANGES.txt index 3f9447e..694d8f9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,12 @@ Changes Next release ------------ +- When ``colander.null`` was unpickled, the reference created during + unpickling was *not* a reference to the singleton but rather a new instance + of the ``colander._null`` class. This was unintentional, because lots of + code checks for ``if x is colander.null``, which will fail across pickling + and unpickling. Now the reference created when ``colander.null`` is + pickled is unpickled as the singleton itself. 0.9 (2010-11-28) ----------------- diff --git a/colander/__init__.py b/colander/__init__.py index 4d88226..be6901d 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -18,6 +18,9 @@ class _null(object): def __repr__(self): return '' + def __reduce__(self): + return 'null' # when unpickled, refers to "null" below (singleton) + null = _null() def interpolate(msgs): diff --git a/colander/tests.py b/colander/tests.py index 070c0ac..22d1f5f 100644 --- a/colander/tests.py +++ b/colander/tests.py @@ -1854,6 +1854,11 @@ class Test_null(unittest.TestCase): from colander import null self.assertEqual(repr(null), '') + def test_pickling(self): + from colander import null + import cPickle + self.failUnless(cPickle.loads(cPickle.dumps(null)) is null) + class Dummy(object): pass