summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/engine/base.py25
-rw-r--r--test/sql/test_query.py5
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 36365e524..db19fe7de 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 bcbb15ace..9725d3d3a 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