From 68c247358b2905b6992fa7fe935e80b7f41b36d6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 12 Jan 2009 15:58:09 +0000 Subject: [PATCH] Ensure RowTuple names are correct by adding "key" to QueryableAttribute. --- lib/sqlalchemy/orm/attributes.py | 8 ++------ lib/sqlalchemy/orm/query.py | 2 +- test/orm/mapper.py | 5 +++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 1606f82674..d7c2e8772f 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -99,7 +99,7 @@ class QueryableAttribute(interfaces.PropComparator): comparator a sql.Comparator to which class-level compare/math events will be sent """ - + self.key = key self.impl = impl self.comparator = comparator self.parententity = parententity @@ -182,7 +182,7 @@ def proxied_attribute_factory(descriptor): self._parententity = parententity self.impl = _ProxyImpl(key) - @property + @util.memoized_property def comparator(self): if util.callable(self._comparator): self._comparator = self._comparator() @@ -218,10 +218,6 @@ def proxied_attribute_factory(descriptor): attribute) ) - def _property(self): - return self._parententity.get_property(self.key, resolve_synonyms=True) - property = property(_property) - Proxy.__name__ = type(descriptor).__name__ + 'Proxy' util.monkeypatch_proxied_specials(Proxy, type(descriptor), diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index f225f346a2..e540ce21e2 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1823,7 +1823,7 @@ class _ColumnEntity(_QueryEntity): column = sql.literal_column(column) self._result_label = column.name elif isinstance(column, attributes.QueryableAttribute): - self._result_label = column.property.key + self._result_label = column.key column = column.__clause_element__() else: self._result_label = getattr(column, 'key', None) diff --git a/test/orm/mapper.py b/test/orm/mapper.py index c8a24babc7..eaceb9230f 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -658,6 +658,11 @@ class MapperTest(_fixtures.FixtureTest): assert User.adlist.property sess = create_session() + + # test RowTuple names + row = sess.query(User.id, User.uname).first() + assert row.uname == row[1] + u = sess.query(User).filter(User.uname=='jack').one() fixture = self.static.user_address_result[0].addresses -- 2.47.3