]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merged r4861, session.is_active, from trunk
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 17 Jun 2008 20:55:05 +0000 (20:55 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 17 Jun 2008 20:55:05 +0000 (20:55 +0000)
CHANGES
lib/sqlalchemy/orm/session.py
test/orm/session.py

diff --git a/CHANGES b/CHANGES
index 3e53e00bce4b1b9b282e5109164d82750771a454..e6572d368e147b1d227aaf0b2bfe40cc9870aa4d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -22,6 +22,11 @@ CHANGES
       mapper inheritance against the target mapper are 
       still not allowed.
 
+    - Added is_active flag to Sessions to detect when 
+      a transaction is in progress [ticket:976].  This
+      flag is always True with a "transactional" 
+      (in 0.5 a non-"autocommit") Session.
+    
 - postgres
     - Repaired server_side_cursors to properly detect 
       text() clauses.
index 072db4392160c894c89141f279b28d72241ad040..3dfe0411c379fb4c0a4eaa08879aa77095759da8 100644 (file)
@@ -1173,7 +1173,13 @@ class Session(object):
             if added or deleted:
                 return True
         return False
-
+    
+    def is_active(self):
+        """return True if this Session has an active transaction."""
+        
+        return self.transaction and self.transaction.is_active
+    is_active = property(is_active)
+    
     def dirty(self):
         """Return a ``Set`` of all instances marked as 'dirty' within this ``Session``.
 
index 49932f8d9d78718012a47b1feeb8e09f9631530f..eae0eab1124df59ad9e3381131ffd99deb196747 100644 (file)
@@ -6,7 +6,7 @@ from sqlalchemy.orm.session import SessionExtension
 from sqlalchemy.orm.session import Session as SessionCls
 from testlib import *
 from testlib.tables import *
-from testlib import fixtures, tables
+from testlib import fixtures, tables, config
 import pickle
 import gc
 
@@ -245,6 +245,13 @@ class SessionTest(TestBase, AssertsExecutionResults):
         assert len(u.addresses) == 3
         assert newad not in u.addresses
 
+    def test_active_flag(self):
+        sess = create_session(bind=config.db, transactional=False)
+        assert not sess.is_active
+        sess.begin()
+        assert sess.is_active
+        sess.rollback()
+        assert not sess.is_active
 
     @engines.close_open_connections
     def test_external_joined_transaction(self):