From 74a8723df35fb35869fe95af5128ab6acd527a79 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 28 Apr 2010 16:16:56 -0400 Subject: [PATCH] - Fixed bug in connection pool cursor wrapper whereby if a cursor threw an exception on close(), the logging of the message would fail. [ticket:1786] --- CHANGES | 4 ++++ lib/sqlalchemy/pool.py | 2 +- test/engine/test_reconnect.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index e66480da51..0bc7275b96 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,10 @@ CHANGES - Fixed "table" argument on constructor of ForeginKeyConstraint [ticket:1571] + - Fixed bug in connection pool cursor wrapper whereby if a + cursor threw an exception on close(), the logging of the + message would fail. [ticket:1786] + - engines - Fixed building the C extensions on Python 2.4. [ticket:1781] diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 31ab7facc5..ef13238929 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -454,7 +454,7 @@ class _CursorFairy(object): ex_text = str(e) except TypeError: ex_text = repr(e) - self.__parent._logger.warn("Error closing cursor: %s", ex_text) + self._parent._logger.warn("Error closing cursor: %s", ex_text) if isinstance(e, (SystemExit, KeyboardInterrupt)): raise diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py index 6afd715155..117ef05eea 100644 --- a/test/engine/test_reconnect.py +++ b/test/engine/test_reconnect.py @@ -177,6 +177,34 @@ class MockReconnectTest(TestBase): assert not conn.invalidated assert len(dbapi.connections) == 1 +class CursorErrTest(TestBase): + + def setup(self): + global db, dbapi + + class MDBAPI(MockDBAPI): + def connect(self, *args, **kwargs): + return MConn(self) + + class MConn(MockConnection): + def cursor(self): + return MCursor(self) + + class MCursor(MockCursor): + def close(self): + raise Exception("explode") + + dbapi = MDBAPI() + + # create engine using our current dburi + db = tsa.create_engine('postgresql://foo:bar@localhost/test', module=dbapi, _initialize=False) + + def test_cursor_explode(self): + conn = db.connect() + result = conn.execute("select foo") + result.close() + conn.close() + engine = None class RealReconnectTest(TestBase): def setup(self): -- 2.47.2