From: Mike Bayer Date: Mon, 5 May 2008 16:46:24 +0000 (+0000) Subject: - same as [ticket:1019] but repaired the non-labeled use case X-Git-Tag: rel_0_5beta1~152 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd5543b78e071a24652ab040c3029b7aea29f7d7;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - same as [ticket:1019] but repaired the non-labeled use case [ticket:1022] --- diff --git a/CHANGES b/CHANGES index 4ac82c2edc..f23004f71b 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 d7c7cebaa8..583a027638 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 1143bf8aa4..269d31661e 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 b7ebc31a45..b320f226a4 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()