]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix result set handling for case insensitive dupe cols
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Apr 2016 14:36:19 +0000 (10:36 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Apr 2016 14:36:19 +0000 (10:36 -0400)
Fixed bug where when using ``case_sensitive=False`` with an
:class:`.Engine`, the result set would fail to correctly accomodate
for duplicate column names in the result set, causing an error
when the statement is executed in 1.0, and preventing the
"ambiguous column" exception from functioning in 1.1.

Change-Id: If582bb9fdd057e4da3ae42f7180b17d1a1a2d98e
Fixes: #3690
doc/build/changelog/changelog_10.rst
lib/sqlalchemy/engine/result.py
test/sql/test_resultset.py

index 07188b7711e97af38c2c0edac99c7b3ed2194739..f5de4f763238900427acdef6936c625433d82447 100644 (file)
 .. changelog::
     :version: 1.0.13
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3690
+
+        Fixed bug where when using ``case_sensitive=False`` with an
+        :class:`.Engine`, the result set would fail to correctly accomodate
+        for duplicate column names in the result set, causing an error
+        when the statement is executed in 1.0, and preventing the
+        "ambiguous column" exception from functioning in 1.1.
+
     .. change::
         :tags: bug, sql
         :tickets: 3682
index 0333d9ec238fd2e4b7a6f6365e873bcc2db43e17..773022ed2b34e8a93d77c5a576a3250f0faa7722 100644 (file)
@@ -257,6 +257,7 @@ class ResultMetaData(object):
                     if key in seen:
                         # this is an "ambiguous" element, replacing
                         # the full record in the map
+                        key = key.lower() if not self.case_sensitive else key
                         by_key[key] = (None, key, None)
                     seen.add(key)
 
index ba85fb82e342e1e2587879dd2cafe84ff52c95e5..f74e51f620897f2efd34d93c1637008f0b5df277 100644 (file)
@@ -688,6 +688,21 @@ class ResultProxyTest(fixtures.TablesTest):
             lambda: row[u2.c.user_id]
         )
 
+    @testing.requires.duplicate_names_in_cursor_description
+    def test_ambiguous_column_case_sensitive(self):
+        eng = engines.testing_engine(options=dict(case_sensitive=False))
+
+        row = eng.execute(select([
+            literal_column('1').label('SOMECOL'),
+            literal_column('1').label('SOMECOL'),
+        ])).first()
+
+        assert_raises_message(
+            exc.InvalidRequestError,
+            "Ambiguous column name",
+            lambda: row['somecol']
+        )
+
     @testing.requires.duplicate_names_in_cursor_description
     def test_ambiguous_column_contains(self):
         users = self.tables.users