- 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:
@@ -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)
|
||||||
-----------------
|
-----------------
|
||||||
|
@@ -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):
|
||||||
|
@@ -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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user