]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug whereby if a database restart
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Jun 2012 16:42:01 +0000 (12:42 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Jun 2012 16:42:01 +0000 (12:42 -0400)
affected multiple connections, each
connection would individually invoke a new
disposal of the pool, even though only
one disposal is needed.  [ticket:2522]

CHANGES
lib/sqlalchemy/engine/base.py
test/engine/test_reconnect.py

diff --git a/CHANGES b/CHANGES
index 9721775f7bf4c60935bc25b73cea3e19110077b6..bed5bd1fa77d1671e5808ac58734fd87a942961b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -157,6 +157,12 @@ underneath "0.7.xx".
     the new pool.  This fix may or may
     not be ported to 0.7.  [ticket:2522]
 
+  - [bug] Fixed bug whereby if a database restart
+    affected multiple connections, each 
+    connection would individually invoke a new
+    disposal of the pool, even though only 
+    one disposal is needed.  [ticket:2522]
+
   - [feature] Added a new system
     for registration of new dialects in-process
     without using an entrypoint.  See the
index 75f6ac29a68595d739586df8f303abeb54bf6bc0..2972752232ac4c94ef8386e3cbb82ca9acbc2fe2 100644 (file)
@@ -1833,8 +1833,11 @@ class Connection(Connectable):
 
 
             if is_disconnect:
+                dbapi_conn_wrapper = self.connection
                 self.invalidate(e)
-                self.engine.dispose()
+                if not hasattr(dbapi_conn_wrapper, '_pool') or \
+                    dbapi_conn_wrapper._pool is self.engine.pool:
+                    self.engine.dispose()
             else:
                 if cursor:
                     self._safe_close_cursor(cursor)
index b545aca523bfa9ebdb07b6875fb5dd1cb2c13f0f..da9e54292546709c00e1c7675f22e8796824d4c7 100644 (file)
@@ -264,6 +264,33 @@ class RealReconnectTest(fixtures.TestBase):
 
         conn.close()
 
+    def test_multiple_invalidate(self):
+        c1 = engine.connect()
+        c2 = engine.connect()
+
+        eq_(c1.execute(select([1])).scalar(), 1)
+
+        p1 = engine.pool
+        engine.test_shutdown()
+
+        try:
+            c1.execute(select([1]))
+            assert False
+        except tsa.exc.DBAPIError, e:
+            assert e.connection_invalidated
+
+        p2 = engine.pool
+
+        try:
+            c2.execute(select([1]))
+            assert False
+        except tsa.exc.DBAPIError, e:
+            assert e.connection_invalidated
+
+        # pool isn't replaced
+        assert engine.pool is p2
+
+
     def test_ensure_is_disconnect_gets_connection(self):
         def is_disconnect(e, conn, cursor):
             # connection is still present