[Zodb-checkins] SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/ Fix semantics for 'del obj._p_changed'.
Tres Seaver
tseaver at palladion.com
Tue Feb 15 12:37:06 EST 2011
Log message for revision 120348:
Fix semantics for 'del obj._p_changed'.
Unlike assigning 'obj._p_changed = None', deleting must unconditionally
invalidate the object.
Changed:
U ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py
U ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py
-=-
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py 2011-02-15 15:55:24 UTC (rev 120347)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py 2011-02-15 17:37:06 UTC (rev 120348)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2003 Zope Foundation and Contributors.
+# Copyright (c) 2011 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -48,6 +48,7 @@
if not IPersistentDataManager.providedBy(value):
raise ValueError('Not a data manager: %s' % value)
self.__jar = value
+
_p_jar = property(_get_jar, _set_jar)
# _p_oid: see IPersistent.
@@ -91,15 +92,13 @@
self._set_changed_flag(value)
else:
if value is None: # -> ghost
- if self.__flags & _STICKY:
- raise ValueError('Sticky')
if not self.__flags & _CHANGED:
self._p_invalidate()
else:
self._set_changed_flag(value)
def _del_changed(self):
- self._set_changed(None)
+ self._p_invalidate()
_p_changed = property(_get_changed, _set_changed, _del_changed)
@@ -163,7 +162,8 @@
def _p_invalidate(self):
""" See IPersistent.
"""
- # XXX check
+ if self.__flags is not None and self.__flags & _STICKY:
+ raise ValueError('Sticky')
self.__flags = None
# Helper methods: not APIs
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py 2011-02-15 15:55:24 UTC (rev 120347)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py 2011-02-15 17:37:06 UTC (rev 120348)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2003 Zope Foundation and Contributors.
+# Copyright (c) 2011 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -259,8 +259,7 @@
inst = self._makeOne()
inst._p_changed = True
del inst._p_changed
- # can't transition 'unsaved' -> 'new'
- self.assertEqual(inst._p_state, 'unsaved')
+ self.assertEqual(inst._p_state, 'new')
def test_delete_p_changed_from_ghost(self):
inst, jar, OID = self._makeOneWithJar()
@@ -286,8 +285,7 @@
jar._loaded = []
jar._registered = []
del inst._p_changed
- # del is ignored when dirty
- self.assertEqual(inst._p_state, 'changed')
+ self.assertEqual(inst._p_state, 'ghost')
self.assertEqual(list(jar._loaded), [])
self.assertEqual(list(jar._registered), [])
More information about the Zodb-checkins
mailing list