]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed regression where new methods on :class:`.ResultProxy` used
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Jul 2015 20:32:31 +0000 (16:32 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Jul 2015 20:32:31 +0000 (16:32 -0400)
by the ORM :class:`.Query` object (part of the performance
enhancements of :ticket:`3175`) would not raise the "this result
does not return rows" exception in the case where the driver
(typically MySQL) fails to generate cursor.description correctly;
an AttributeError against NoneType would be raised instead.
fixes #3481

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/engine/result.py
test/sql/test_query.py

index 1e00ddcd4663b5fcedf1d029f174a5a8d673bb98..a2b4273bf684a395f3f2f00f99643951fd3a966f 100644 (file)
 .. changelog::
     :version: 1.0.7
 
+    .. change::
+        :tags: bug, engine
+        :tickets: 3481
+
+        Fixed regression where new methods on :class:`.ResultProxy` used
+        by the ORM :class:`.Query` object (part of the performance
+        enhancements of :ticket:`3175`) would not raise the "this result
+        does not return rows" exception in the case where the driver
+        (typically MySQL) fails to generate cursor.description correctly;
+        an AttributeError against NoneType would be raised instead.
+
     .. change::
         :tags: bug, engine
         :tickets: 3483
index 3fcab873bfcb81c8a0bdd141242019ab9cb43f2f..74a0fce771f96bce6abbb63610fd1128ed5403b5 100644 (file)
@@ -495,10 +495,20 @@ class ResultProxy(object):
         self._init_metadata()
 
     def _getter(self, key):
-        return self._metadata._getter(key)
+        try:
+            getter = self._metadata._getter
+        except AttributeError:
+            return self._non_result(None)
+        else:
+            return getter(key)
 
     def _has_key(self, key):
-        return self._metadata._has_key(key)
+        try:
+            has_key = self._metadata._has_key
+        except AttributeError:
+            return self._non_result(None)
+        else:
+            return has_key(key)
 
     def _init_metadata(self):
         metadata = self._cursor_description()
index 16ba285b2bb03a5a1cfcde54b2637fece4ad2275..0313a9cd09c95c79b78cd86a03cb35cac39321b5 100644 (file)
@@ -976,14 +976,22 @@ class QueryTest(fixtures.TestBase):
         # result.BufferedColumnResultProxy
 
         conn = testing.db.connect()
-        for meth in ('fetchone', 'fetchall', 'first', 'scalar', 'fetchmany'):
+        for meth in [
+            lambda r: r.fetchone(),
+            lambda r: r.fetchall(),
+            lambda r: r.first(),
+            lambda r: r.scalar(),
+            lambda r: r.fetchmany(),
+            lambda r: r._getter('user'),
+            lambda r: r._has_key('user'),
+        ]:
             trans = conn.begin()
             result = conn.execute(users.insert(), user_id=1)
             assert_raises_message(
                 exc.ResourceClosedError,
                 "This result object does not return rows. "
                 "It has been closed automatically.",
-                getattr(result, meth),
+                meth, result,
             )
             trans.rollback()