[Zodb-checkins] SVN: ZODB/branches/tim-deprecate-subtxn/ Most of
the way toward deprecating subtransactions.
Tim Peters
tim.one at comcast.net
Wed Jul 13 18:48:59 EDT 2005
Log message for revision 33305:
Most of the way toward deprecating subtransactions.
At least one test is still spewing a visible deprecation wng
to the screen, but it's maddening: test_beforeCommitHook()
doesn't give a visible wng when run in isolation, it only happens
when the whole test suite is run.
Changed:
U ZODB/branches/tim-deprecate-subtxn/NEWS.txt
U ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testConnection.py
U ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testSubTransaction.py
U ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testZODB.py
U ZODB/branches/tim-deprecate-subtxn/src/ZODB/utils.py
U ZODB/branches/tim-deprecate-subtxn/src/transaction/_manager.py
U ZODB/branches/tim-deprecate-subtxn/src/transaction/_transaction.py
U ZODB/branches/tim-deprecate-subtxn/src/transaction/tests/test_transaction.py
-=-
Modified: ZODB/branches/tim-deprecate-subtxn/NEWS.txt
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/NEWS.txt 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/NEWS.txt 2005-07-13 22:48:58 UTC (rev 33305)
@@ -27,16 +27,16 @@
marked a savepoint as invalid after its first use. The implementation has
been repaired, to match the docs.
-Subtransactions
----------------
+Subtransactions are deprecated
+------------------------------
-- (3.5a4) Internal uses of subtransactions (transaction ``commit()`` or
- ``abort()`` passing a true argument) were rewritten to use savepoints
- instead. Application code is strongly encouraged to do this too:
- subtransactions are weaker, will be deprecated soon, and do not mix well
- with savepoints (when you do a subtransaction commit, all current
- savepoints are made unusable). In general, a subtransaction commit
- done just to free memory can be changed from::
+- (3.5a4) Subtransactions are deprecated, and will be removed in ZODB 3.7.
+ Use savepoints instead. Savepoints are more powerful, and code using
+ subtransactions does not mix well with code using savepoints (a
+ subtransaction commit forces all current savepoints to become unusable, so
+ code using subtransactions can hurt newer code trying to use savepoints).
+ In general, a subtransaction commit done just to free memory can be changed
+ from::
transaction.commit(1)
@@ -62,6 +62,10 @@
sp.rollback()
+- (3.5a4) Internal uses of subtransactions (transaction ``commit()`` or
+ ``abort()`` passing a true argument) were rewritten to use savepoints
+ instead.
+
Multi-database
--------------
Modified: ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testConnection.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testConnection.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -24,6 +24,12 @@
from ZODB.tests.warnhook import WarningsHook
from zope.interface.verify import verifyObject
+# deprecated37 remove when subtransactions go away
+# Don't complain about subtxns in these tests.
+warnings.filterwarnings("ignore",
+ ".*\nsubtransactions are deprecated",
+ DeprecationWarning, __name__)
+
class ConnectionDotAdd(unittest.TestCase):
def setUp(self):
@@ -316,6 +322,11 @@
>>> cn.close()
>>> db.close()
+
+ Obscure: There is no API call for removing the filter we added, but
+ filters appears to be a public variable.
+
+ >>> del warnings.filters[0]
"""
def test_onCloseCallbacks(self):
Modified: ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testSubTransaction.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testSubTransaction.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testSubTransaction.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -11,10 +11,16 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-r"""
+"""
ZODB subtransaction tests
=========================
+Subtransactions are deprecated. First we install a hook, to ensure that
+deprecation warnings are generated.
+
+>>> hook = WarningsHook()
+>>> hook.install()
+
Subtransactions are provided by a generic transaction interface, but
only supported by ZODB. These tests verify that some of the important
cases work as expected.
@@ -61,6 +67,19 @@
>>> shadow_a.value, shadow_b.value
('a0', 'b0')
+The subtransaction commit should have generated a deprecation wng:
+
+>>> len(hook.warnings)
+1
+>>> message, category, filename, lineno = hook.warnings[0]
+>>> print message
+This will be removed in ZODB 3.7:
+subtransactions are deprecated; use transaction.savepoint() instead of \
+transaction.commit(1)
+>>> category.__name__
+'DeprecationWarning'
+>>> hook.clear()
+
>>> a.value = "a2"
>>> c.value = "c1"
>>> transaction.commit(1)
@@ -100,6 +119,21 @@
>>> a.value, b.value, c.value
('a1', 'b1', 'c0')
+The subtxn abort should also have generated a deprecation warning:
+
+>>> len(hook.warnings)
+1
+>>> message, category, filename, lineno = hook.warnings[0]
+>>> print message
+This will be removed in ZODB 3.7:
+subtransactions are deprecated; use sp.rollback() instead of \
+transaction.abort(1), where `sp` is the corresponding savepoint \
+captured earlier
+>>> category.__name__
+'DeprecationWarning'
+>>> hook.clear()
+
+
Multiple aborts have no extra effect.
>>> transaction.abort(1)
@@ -131,8 +165,14 @@
>>> a.value, b.value, c.value
('a0', 'b0', 'c0')
+We have to uninstall the hook so that other warnings don't get lost.
+
+>>> len(hook.warnings) # we don't expect we captured other warnings
+0
+>>> hook.uninstall()
"""
+from ZODB.tests.warnhook import WarningsHook
from zope.testing import doctest
def test_suite():
Modified: ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testZODB.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testZODB.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/ZODB/tests/testZODB.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -12,6 +12,7 @@
#
##############################################################################
import unittest
+import warnings
import ZODB
import ZODB.FileStorage
@@ -23,6 +24,12 @@
from persistent.mapping import PersistentMapping
import transaction
+# deprecated37 remove when subtransactions go away
+# Don't complain about subtxns in these tests.
+warnings.filterwarnings("ignore",
+ ".*\nsubtransactions are deprecated",
+ DeprecationWarning, __name__)
+
class P(Persistent):
pass
@@ -622,12 +629,28 @@
poisoned = PoisonedJar()
transaction.get().join(poisoned)
poisoned.break_savepoint = True
- self.assertRaises(PoisonedError, transaction.get().commit, True)
+ # We're using try/except here instead of assertRaises so that this
+ # module's attempt to suppress subtransaction deprecation wngs
+ # work.
+ try:
+ transaction.get().commit(True)
+ except PoisonedError:
+ pass
+ else:
+ self.fail("expected PoisonedError")
# Trying to subtxn-commit again fails too.
- self.assertRaises(TransactionFailedError,
- transaction.get().commit, True)
- self.assertRaises(TransactionFailedError,
- transaction.get().commit, True)
+ try:
+ transaction.get().commit(True)
+ except TransactionFailedError:
+ pass
+ else:
+ self.fail("expected TransactionFailedError")
+ try:
+ transaction.get().commit(True)
+ except TransactionFailedError:
+ pass
+ else:
+ self.fail("expected TransactionFailedError")
# Top-level commit also fails.
self.assertRaises(TransactionFailedError, transaction.get().commit)
@@ -651,9 +674,19 @@
poisoned = PoisonedJar()
transaction.get().join(poisoned)
poisoned.break_savepoint = True
- self.assertRaises(PoisonedError, transaction.get().commit, True)
- self.assertRaises(TransactionFailedError,
- transaction.get().commit, True)
+ try:
+ transaction.commit(True)
+ except PoisonedError:
+ pass
+ else:
+ self.fail("expected PoisonedError")
+ # Trying to subtxn-commit again fails too.
+ try:
+ transaction.commit(True)
+ except TransactionFailedError:
+ pass
+ else:
+ self.fail("expected TransactionFailedError")
# The change to rt['a'] is lost.
self.assertEqual(rt['a'], 1)
Modified: ZODB/branches/tim-deprecate-subtxn/src/ZODB/utils.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/ZODB/utils.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/ZODB/utils.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -38,6 +38,7 @@
'WeakSet',
'DEPRECATED_ARGUMENT',
'deprecated36',
+ 'deprecated37',
'get_pickle_metadata',
]
@@ -57,6 +58,13 @@
warnings.warn("This will be removed in ZODB 3.6:\n%s" % msg,
DeprecationWarning, stacklevel=3)
+# Raise DeprecationWarning, noting that the deprecated thing will go
+# away in ZODB 3.7. Point to the caller of our caller (i.e., at the
+# code using the deprecated thing).
+def deprecated37(msg):
+ warnings.warn("This will be removed in ZODB 3.7:\n%s" % msg,
+ DeprecationWarning, stacklevel=3)
+
z64 = '\0'*8
assert sys.hexversion >= 0x02030000
Modified: ZODB/branches/tim-deprecate-subtxn/src/transaction/_manager.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/transaction/_manager.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/transaction/_manager.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -21,6 +21,11 @@
from transaction._transaction import Transaction
+# Used for deprecated arguments. ZODB.utils.DEPRECATED_ARGUMENT is
+# too hard to use here, due to the convoluted import dance across
+# __init__.py files.
+_marker = object()
+
# We have to remember sets of synch objects, especially Connections.
# But we don't want mere registration with a transaction manager to
# keep a synch object alive forever; in particular, it's common
@@ -80,11 +85,26 @@
def unregisterSynch(self, synch):
self._synchs.remove(synch)
- def commit(self, sub=False):
- self.get().commit(sub)
+ def commit(self, sub=_marker):
+ if sub is _marker:
+ sub = None
+ else:
+ from ZODB.utils import deprecated37
+ deprecated37("subtransactions are deprecated; use "
+ "transaction.savepoint() instead of "
+ "transaction.commit(1)")
+ return self.get().commit(sub, deprecation_wng=False)
- def abort(self, sub=False):
- self.get().abort(sub)
+ def abort(self, sub=_marker):
+ if sub is _marker:
+ sub = None
+ else:
+ from ZODB.utils import deprecated37
+ deprecated37("subtransactions are deprecated; use "
+ "sp.rollback() instead of "
+ "transaction.abort(1), where `sp` is the "
+ "corresponding savepoint captured earlier")
+ return self.get().abort(sub, deprecation_wng=False)
def savepoint(self, optimistic=False):
return self.get().savepoint(optimistic)
Modified: ZODB/branches/tim-deprecate-subtxn/src/transaction/_transaction.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/transaction/_transaction.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/transaction/_transaction.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -358,7 +358,15 @@
# in which case it would do nothing besides uselessly free() this
# transaction.
- def commit(self, subtransaction=False):
+ def commit(self, subtransaction=_marker, deprecation_wng=True):
+ if subtransaction is _marker:
+ subtransaction = 0
+ elif deprecation_wng:
+ from ZODB.utils import deprecated37
+ deprecated37("subtransactions are deprecated; use "
+ "transaction.savepoint() instead of "
+ "transaction.commit(1)")
+
if self._savepoint2index:
self._invalidate_all_savepoints()
@@ -464,7 +472,16 @@
self.log.error("Error in tpc_abort() on manager %s",
rm, exc_info=sys.exc_info())
- def abort(self, subtransaction=False):
+ def abort(self, subtransaction=_marker, deprecation_wng=True):
+ if subtransaction is _marker:
+ subtransaction = 0
+ elif deprecation_wng:
+ from ZODB.utils import deprecated37
+ deprecated37("subtransactions are deprecated; use "
+ "sp.rollback() instead of "
+ "transaction.abort(1), where `sp` is the "
+ "corresponding savepoint captured earlier")
+
if subtransaction:
# TODO deprecate subtransactions.
if not self._subtransaction_savepoint:
Modified: ZODB/branches/tim-deprecate-subtxn/src/transaction/tests/test_transaction.py
===================================================================
--- ZODB/branches/tim-deprecate-subtxn/src/transaction/tests/test_transaction.py 2005-07-13 22:39:29 UTC (rev 33304)
+++ ZODB/branches/tim-deprecate-subtxn/src/transaction/tests/test_transaction.py 2005-07-13 22:48:58 UTC (rev 33305)
@@ -40,9 +40,17 @@
"""
import unittest
+import warnings
+
import transaction
from ZODB.utils import positive_id
+# deprecated37 remove when subtransactions go away
+# Don't complain about subtxns in these tests.
+warnings.filterwarnings("ignore",
+ ".*\nsubtransactions are deprecated",
+ DeprecationWarning, __name__)
+
class TransactionTests(unittest.TestCase):
def setUp(self):
@@ -212,7 +220,8 @@
try:
self.transaction_manager.commit()
- except TestTxnException: pass
+ except TestTxnException:
+ pass
assert self.nosub1._p_jar.ctpc_abort == 1
assert self.sub1._p_jar.ctpc_abort == 1
@@ -444,10 +453,14 @@
>>> log
[]
- The hook is only called for a full commit, not for subtransactions.
+ The hook is only called for a full commit, not for a savepoint or
+ subtransaction.
>>> t = transaction.begin()
>>> t.beforeCommitHook(hook, 'A', kw1='B')
+ >>> dummy = t.savepoint()
+ >>> log
+ []
>>> t.commit(subtransaction=True)
>>> log
[]
More information about the Zodb-checkins
mailing list