]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Issue a better error message when someone decides to meddle with the active transacti...
authorAnts Aasma <ants.aasma@gmail.com>
Tue, 30 Sep 2008 12:04:23 +0000 (12:04 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Tue, 30 Sep 2008 12:04:23 +0000 (12:04 +0000)
lib/sqlalchemy/orm/session.py

index cbff0ef0d1675c8491d0d0d187af1e003ea9bbaf..d4d512034ed01d361b1c1b14ef99c07723b4d048 100644 (file)
@@ -244,9 +244,9 @@ class SessionTransaction(object):
                 "The transaction is inactive due to a rollback in a "
                 "subtransaction.  Issue rollback() to cancel the transaction.")
 
-    def _assert_is_open(self):
+    def _assert_is_open(self, error_msg="The transaction is closed"):
         if self.session is None:
-            raise sa_exc.InvalidRequestError("The transaction is closed")
+            raise sa_exc.InvalidRequestError(error_msg)
 
     @property
     def _is_transaction_boundary(self):
@@ -438,6 +438,7 @@ class SessionTransaction(object):
         return self
 
     def __exit__(self, type, value, traceback):
+        self._assert_is_open("Cannot end transaction context. The transaction was closed from within the context")
         if self.session.transaction is None:
             return
         if type is None: