summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-17 21:20:49 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-17 21:20:49 +0000
commitde1712a2116d80a6771ad5475277cc85e87179e2 (patch)
tree58f7f038b9259d01b91f6df36bdaf5305472bd03 /lib
parent99b1bee20e20ddb74b1ade6b186f6f7a174968a2 (diff)
downloadsqlalchemy-de1712a2116d80a6771ad5475277cc85e87179e2.tar.gz
- added close() method to Transaction. closes out a transaction using rollback
if it's the outermost transaction, otherwise just ends without affecting the outer transaction. - transactional and non-transactional Session integrates better with bound connection; a close() will ensure that connection transactional state is the same as that which existed on it before being bound to the Session.
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/engine/base.py14
-rw-r--r--lib/sqlalchemy/orm/session.py2
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 8fe34bf3f..faeb00cc9 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -864,6 +864,20 @@ class Transaction(object):
connection = property(lambda s:s._connection, doc="The Connection object referenced by this Transaction")
is_active = property(lambda s:s._is_active)
+ def close(self):
+ """close this transaction.
+
+ If this transaction is the base transaction in a begin/commit nesting,
+ the transaction will rollback(). Otherwise, the method returns.
+
+ This is used to cancel a Transaction without affecting the scope of
+ an enclosign transaction.
+ """
+ if not self._parent._is_active:
+ return
+ if self._parent is self:
+ self.rollback()
+
def rollback(self):
if not self._parent._is_active:
return
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index f21d8d69b..5a91f8fbf 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -243,7 +243,7 @@ class SessionTransaction(object):
if t[2]:
t[0].close()
else:
- t[1].rollback()
+ t[1].close()
self.session.transaction = None
def __enter__(self):