- 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.
This commit is contained in:
Chris McDonough
2010-12-02 16:13:25 +00:00
parent f8e9b67b67
commit 13fa908e82
3 changed files with 14 additions and 0 deletions

View File

@@ -4,6 +4,12 @@ Changes
Next release 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) 0.9 (2010-11-28)
----------------- -----------------

View File

@@ -18,6 +18,9 @@ class _null(object):
def __repr__(self): def __repr__(self):
return '<colander.null>' return '<colander.null>'
def __reduce__(self):
return 'null' # when unpickled, refers to "null" below (singleton)
null = _null() null = _null()
def interpolate(msgs): def interpolate(msgs):

View File

@@ -1854,6 +1854,11 @@ class Test_null(unittest.TestCase):
from colander import null from colander import null
self.assertEqual(repr(null), '<colander.null>') self.assertEqual(repr(null), '<colander.null>')
def test_pickling(self):
from colander import null
import cPickle
self.failUnless(cPickle.loads(cPickle.dumps(null)) is null)
class Dummy(object): class Dummy(object):
pass pass