dupe col logic when case sensitive is false

Issue #3690 resolved
Mike Bayer repo owner created an issue

is worse on 1.0, but fails on 1.1 thus:

from sqlalchemy import create_engine, select, literal_column

e = create_engine("sqlite://", case_sensitive=False)

row = e.execute(select([
    literal_column('1').label('SOMECOL'),
    literal_column('1').label('SOMECOL'),
])).first()

row['somecol']

the lookup should raise ambiguous column. on 1.1 it doesn't. On 1.0 we get an error when it's trying to set up the dupe lookup.

fix is likely:

1.0:

diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index 850bc62..a4bfa02 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)

1.1:

diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index 0333d9e..773022e 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -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)

Comments (3)

  1. Mike Bayer reporter

    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

    → <<cset 1f3e5d9826fe>>

  2. Mike Bayer reporter

    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)

    → <<cset 3db48cc62704>>

  3. Log in to comment