From: Mike Bayer Date: Sat, 23 Apr 2011 02:17:43 +0000 (-0400) Subject: grumpy fix X-Git-Tag: rel_0_7_0~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b2a76c4a3ac49997d1ef0a1a542bd2842abf7c5;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git grumpy fix --- diff --git a/CHANGES b/CHANGES index 54744b5a9a..6ba8738440 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,11 @@ CHANGES [ticket:2144] - sql + - Some improvements to error handling inside + of the execute procedure to ensure auto-close + connections are really closed when very + unusual DBAPI errors occur. + - Added explicit check for when Column .name is assigned as blank string [ticket:2140] diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 00eae60a1c..31fdd7fb0a 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1640,11 +1640,10 @@ class Connection(Connectable): try: # non-DBAPI error - if we already got a context, # or theres no string statement, don't wrap it - if not isinstance(e, self.dialect.dbapi.Error) and \ - (statement is None or context is not None): - return + should_wrap = isinstance(e, self.dialect.dbapi.Error) or \ + (statement is not None and context is None) - if context: + if should_wrap and context: context.handle_dbapi_exception(e) is_disconnect = isinstance(e, self.dialect.dbapi.Error) and \ @@ -1658,6 +1657,10 @@ class Connection(Connectable): self._autorollback() if self.should_close_with_result: self.close() + + if not should_wrap: + return + # Py3K #raise exc.DBAPIError.instance( # statement, @@ -2484,7 +2487,12 @@ class ResultProxy(object): uses ``returning()``. """ - return self.context.rowcount + try: + return self.context.rowcount + except Exception, e: + self.connection._handle_dbapi_exception( + e, None, None, self.cursor, self.context) + raise @property def lastrowid(self): @@ -2501,7 +2509,13 @@ class ResultProxy(object): regardless of database backend. """ - return self._saved_cursor.lastrowid + try: + return self._saved_cursor.lastrowid + except Exception, e: + self.connection._handle_dbapi_exception( + e, None, None, + self._saved_cursor, self.context) + raise @property def returns_rows(self): diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 8cdcdc097f..d5defc2a2c 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -424,6 +424,7 @@ class ResultProxyTest(fixtures.TestBase): finally: engine.dialect.execution_ctx_cls = execution_ctx_cls + @testing.requires.python26 def test_rowproxy_is_sequence(self): import collections