Commit 2712b125 authored by Jim Fulton's avatar Jim Fulton

Added a test for a the "bug":

- Object ids created in a savepoint that is rolled back wren't being
  reused. (https://bugs.launchpad.net/zodb/+bug/588389)
parent a6b17807
...@@ -34,6 +34,9 @@ Bugs fixed ...@@ -34,6 +34,9 @@ Bugs fixed
- The verbose mode of the fstest was broken. - The verbose mode of the fstest was broken.
(https://bugs.launchpad.net/zodb/+bug/475996) (https://bugs.launchpad.net/zodb/+bug/475996)
- Object ids created in a savepoint that is rolled back wren't being
reused. (https://bugs.launchpad.net/zodb/+bug/588389)
3.10.0b6 (2010-09-08) 3.10.0b6 (2010-09-08)
===================== =====================
......
...@@ -15,6 +15,7 @@ import doctest ...@@ -15,6 +15,7 @@ import doctest
import persistent.mapping import persistent.mapping
import transaction import transaction
import unittest import unittest
import ZODB.tests.util
def testAddingThenModifyThenAbort(): def testAddingThenModifyThenAbort():
"""\ """\
...@@ -178,6 +179,57 @@ the wrong state. ...@@ -178,6 +179,57 @@ the wrong state.
1 1
""" """
def testNewOidsGetReusedOnRollback():
"""\
New oids assigned during a transaction should be reused on
rollback, not just on abort.
>>> connection = ZODB.connection(None)
>>> root = connection.root()
Let's make a savepoint (with a real change so that the connection
is involved, otherwise rolling back to the savepoint will just be
an abort).
>>> root._p_changed = True # Important!
>>> sp = transaction.savepoint()
Add an object, and make a new savepoint so that it gets an oid.
>>> root['p'] = p = ZODB.tests.util.P()
>>> sp2 = transaction.savepoint()
>>> p._p_oid
'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01'
Rolling back to the first savepoint unassigns the oid, but not
before invalidating the object. If a custom _p_invalidate method
tries to reactivate the object *during* rollback, a POSKeyError is
raised.
>>> sp.rollback()
>>> p._p_oid is None
True
>>> p._p_jar is None
True
>>> print p._p_changed
False
The rest of the state of p is undefined after the rollback. Using
p in any way from this point is a bad idea.
>>> del p
If we create a new object and add it, the oid is reused.
>>> root['p'] = p = ZODB.tests.util.P()
>>> connection.add(p)
>>> p._p_oid
'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01'
>>> transaction.abort()
"""
def tearDown(test): def tearDown(test):
transaction.abort() transaction.abort()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment