]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed AssertionPool regression bug. A replacement of finalize
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 16 Mar 2011 22:15:27 +0000 (18:15 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 16 Mar 2011 22:15:27 +0000 (18:15 -0400)
logic did the wrong thing, but then also the logic it replaced also
doesn't seem like its needed.  If it is, would rather have a test case
first so its out for now, added tests for assertionpool.  [ticket:2097]

CHANGES
lib/sqlalchemy/pool.py
test/engine/test_pool.py

diff --git a/CHANGES b/CHANGES
index 9eedcae30bba2080aa41cd9e9de37e3c6b3bcacc..660c4a860d73f486aa4f8641ccd17ee1aac91e76 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -78,6 +78,9 @@ CHANGES
     (<eventname>, <fn>), which are applied to the Table 
     before the reflection process begins.
 
+- engine
+  - Fixed AssertionPool regression bug.  [ticket:2097]
+
 - dialect
   - Changed exception raised to ArgumentError when an
     invalid dialect is specified. [ticket:2060]
index 327e4aa1f53e8c60f56979c0e702b9837ddc86f2..a45c2e80b0bf8d52961c9fb3ac099ccf87c6f914 100644 (file)
@@ -60,8 +60,6 @@ def clear_managers():
 class Pool(log.Identified):
     """Abstract base class for connection pools."""
 
-    _no_finalize = False
-
     def __init__(self, 
                     creator, recycle=-1, echo=None, 
                     use_threadlocal=False,
@@ -324,9 +322,6 @@ class _ConnectionRecord(object):
 def _finalize_fairy(connection, connection_record, pool, ref, echo):
     _refs.discard(connection_record)
 
-    if pool._no_finalize:
-        return
-
     if ref is not None and \
                 connection_record.fairy is not ref:
         return
@@ -826,8 +821,6 @@ class AssertionPool(Pool):
     than desired.
 
     """
-    _no_finalize = True
-
     def __init__(self, *args, **kw):
         self._conn = None
         self._checked_out = False
index 4e818894fafb434f3aa4ce369d67d83490cda25d..2df8b9ca292667c319d0a196bb6d8a988c0810d3 100644 (file)
@@ -3,7 +3,7 @@ from sqlalchemy import pool, interfaces, create_engine, select, event
 import sqlalchemy as tsa
 from test.lib import TestBase, testing
 from test.lib.util import gc_collect, lazy_gc
-from test.lib.testing import eq_
+from test.lib.testing import eq_, assert_raises
 
 mcid = 1
 class MockDBAPI(object):
@@ -940,6 +940,24 @@ class SingletonThreadPoolTest(PoolTestBase):
             th.join()
         assert len(p._all_conns) == 3
 
+class AssertionPoolTest(PoolTestBase):
+    def test_connect_error(self):
+        dbapi = MockDBAPI()
+        p = pool.AssertionPool(creator = lambda: dbapi.connect('foo.db'))
+        c1 = p.connect()
+        assert_raises(AssertionError, p.connect)
+
+    def test_connect_multiple(self):
+        dbapi = MockDBAPI()
+        p = pool.AssertionPool(creator = lambda: dbapi.connect('foo.db'))
+        c1 = p.connect()
+        c1.close()
+        c2 = p.connect()
+        c2.close()
+
+        c3 = p.connect()
+        assert_raises(AssertionError, p.connect)
+
 class NullPoolTest(PoolTestBase):
     def test_reconnect(self):
         dbapi = MockDBAPI()