From: Mike Bayer Date: Sun, 22 Jan 2012 22:40:50 +0000 (-0500) Subject: - adjust the test for [ticket:2377] to be less controversial on X-Git-Tag: rel_0_7_5~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37773f34488a5f5d65bf31d5d1b899ea56e6af8a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - adjust the test for [ticket:2377] to be less controversial on problematic backends like Oracle.i - move the check generated in r85017c4310d2 up for both label name/name comparisions, fixes additional mismatches which can occur --- diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 36365e524c..db19fe7de7 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -2641,22 +2641,25 @@ class ResultMetaData(object): result = map.get(key.lower()) # fallback for targeting a ColumnElement to a textual expression # this is a rare use case which only occurs when matching text() - # constructs to ColumnElements, and after a pickle/unpickle roundtrip + # or colummn('name') constructs to ColumnElements, or after a + # pickle/unpickle roundtrip elif isinstance(key, expression.ColumnElement): if key._label and key._label.lower() in map: result = map[key._label.lower()] elif hasattr(key, 'name') and key.name.lower() in map: - # match is only on name. search - # extra hard to make sure this isn't a column/ - # label name overlap + # match is only on name. result = map[key.name.lower()] - - if result[1] is not None: - for obj in result[1]: - if key._compare_name_for_result(obj): - break - else: - result = None + # search extra hard to make sure this + # isn't a column/label name overlap. + # this check isn't currently available if the row + # was unpickled. + if result is not None and \ + result[1] is not None: + for obj in result[1]: + if key._compare_name_for_result(obj): + break + else: + result = None if result is None: if raiseerr: raise exc.NoSuchColumnError( diff --git a/test/sql/test_query.py b/test/sql/test_query.py index bcbb15ace8..9725d3d3a0 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -317,6 +317,7 @@ class QueryTest(fixtures.TestBase): ) self.metadata.create_all(testing.db) testing.db.execute(content.insert().values(type="t1")) + row = testing.db.execute(content.select(use_labels=True)).first() assert content.c.type in row assert bar.c.content_type not in row @@ -327,8 +328,8 @@ class QueryTest(fixtures.TestBase): assert bar.c.content_type not in row assert sql.column('content_type') in row - row = testing.db.execute(select([(content.c.type > "abc").label("content_type")])).first() - assert content.c.type in row + row = testing.db.execute(select([func.now().label("content_type")])).first() + assert content.c.type not in row assert bar.c.content_type not in row assert sql.column('content_type') in row