From: Mike Bayer Date: Thu, 21 Apr 2016 14:36:19 +0000 (-0400) Subject: Fix result set handling for case insensitive dupe cols X-Git-Tag: rel_1_0_13~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3db48cc6270442dabeddfdb711f70f23b6dccb2b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix result set handling for case insensitive dupe cols 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 (cherry picked from commit 1f3e5d9826fe989f2212745f6b3592b2ef9b5e32) --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 07188b7711..f5de4f7632 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,16 @@ .. 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 diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 850bc62ef2..a4bfa02be6 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -304,6 +304,7 @@ class ResultMetaData(object): for rec in raw: key = rec[1] if key in seen: + key = key.lower() if not self.case_sensitive else key by_key[key] = (None, by_key[key][1], None) seen.add(key) diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 2a77fed463..f79318236a 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -707,6 +707,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