summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-05-05 16:46:24 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-05-05 16:46:24 +0000
commitfd5543b78e071a24652ab040c3029b7aea29f7d7 (patch)
treea912aaf5ff10d21c838b0a1efca65427bdc4d41f
parent635e61bdebfc8fefb93cad2550b1342c43b63186 (diff)
downloadsqlalchemy-fd5543b78e071a24652ab040c3029b7aea29f7d7.tar.gz
- same as [ticket:1019] but repaired the non-labeled use case
[ticket:1022]
-rw-r--r--CHANGES5
-rw-r--r--lib/sqlalchemy/engine/base.py7
-rw-r--r--lib/sqlalchemy/sql/expression.py5
-rw-r--r--test/orm/eager_relations.py6
4 files changed, 17 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index 4ac82c2ed..f23004f71 100644
--- a/CHANGES
+++ b/CHANGES
@@ -48,7 +48,10 @@ CHANGES
necessary, btw) will have the label anonymized when
the instance is part of the eager join, to prevent
conflicts with a subquery or column of the same name
- on the parent object. [ticket:1019]
+ on the parent object. [ticket:1019]
+
+ - same as [ticket:1019] but repaired the non-labeled use case
+ [ticket:1022]
- Adjusted class-member inspection durint attribute and
collection instrumentation that could be problematic when
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index d7c7cebaa..583a02763 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -1481,13 +1481,12 @@ class ResultProxy(object):
rec = props[key]
except KeyError:
# fallback for targeting a ColumnElement to a textual expression
- # it would be nice to get rid of this but we make use of it in the case where
- # you say something like query.options(contains_alias('fooalias')) - the matching
- # is done on strings
+ # this is a rare use case which only occurs when matching text()
+ # constructs to ColumnElements
if isinstance(key, expression.ColumnElement):
if key._label and key._label.lower() in props:
return props[key._label.lower()]
- elif key.name.lower() in props:
+ elif hasattr(key, 'name') and key.name.lower() in props:
return props[key.name.lower()]
raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % (str(key)))
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 1143bf8aa..269d31661 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2446,7 +2446,10 @@ class _ColumnElementAdapter(ColumnElement):
key = property(key)
def _label(self):
- return self.elem._label
+ try:
+ return self.elem._label
+ except AttributeError:
+ return self.anon_label
_label = property(_label)
def _copy_internals(self, clone=_clone):
diff --git a/test/orm/eager_relations.py b/test/orm/eager_relations.py
index b7ebc31a4..b320f226a 100644
--- a/test/orm/eager_relations.py
+++ b/test/orm/eager_relations.py
@@ -1045,5 +1045,11 @@ class SubqueryTest(ORMTest):
for user in session.query(User).all():
self.assertEquals(user.query_score, user.prop_score)
+ u = session.query(User).filter_by(name='joe').one()
+ self.assertEquals(u.query_score, u.prop_score)
+
+ for t in (tags_table, users_table):
+ t.delete().execute()
+
if __name__ == '__main__':
testenv.main()