]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
grumpy fix
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Apr 2011 02:17:43 +0000 (22:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Apr 2011 02:17:43 +0000 (22:17 -0400)
CHANGES
lib/sqlalchemy/engine/base.py
test/engine/test_execute.py

diff --git a/CHANGES b/CHANGES
index 54744b5a9a1963f6adcdcd8874e43f5f8260b852..6ba87384407af7a947907cc029347ee0e73c4a2d 100644 (file)
--- 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]
 
index 00eae60a1c4e93d48427ef35b349d55e9de2c426..31fdd7fb0a1528518bb4271b5213e979073b445f 100644 (file)
@@ -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):
index 8cdcdc097f460260bed50220479e52c0257f4f4c..d5defc2a2c2e9df532e4a8567f8a082f90396c86 100644 (file)
@@ -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