From 0afe1ba02d5817f6a46a1ae567a90a5188239981 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 6 Aug 2010 13:19:59 -0400 Subject: - step one, remove "resolve_synonyms" and start using class attribute access to get at mapped properties by name --- lib/sqlalchemy/orm/util.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/orm/util.py') diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index ef5413724..c9004990a 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -347,10 +347,6 @@ class AliasedClass(object): return queryattr def __getattr__(self, key): - prop = self.__mapper._get_property(key, raiseerr=False) - if prop: - return self.__adapt_prop(prop) - for base in self.__target.__mro__: try: attr = object.__getattribute__(base, key) @@ -360,7 +356,10 @@ class AliasedClass(object): break else: raise AttributeError(key) - + + if isinstance(attr, attributes.QueryableAttribute): + return self.__adapt_prop(attr.property) + if hasattr(attr, 'func_code'): is_method = getattr(self.__target, key, None) if is_method and is_method.im_self is not None: @@ -494,7 +493,7 @@ def with_parent(instance, prop): """ if isinstance(prop, basestring): mapper = object_mapper(instance) - prop = mapper.get_property(prop, resolve_synonyms=True) + prop = mapper.get_property(prop) elif isinstance(prop, attributes.QueryableAttribute): prop = prop.property -- cgit v1.2.1 From 6519b0c72cbae6778eff026815cc2b93cfeeabdf Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 6 Aug 2010 18:53:22 -0400 Subject: - at long last have gotten the "proxy_property" keyword arg of register_descriptor to not be needed. synonym, comparable, concreteinherited props now supply a descriptor directly in the class dict, whose __get__(None, cls) supplies a QueryableAttribute. The basic idea is that the hybrid prop can be used for this. Payoff here is arguable, except that hybrid can be at the base of future synonym/comparable operations. --- lib/sqlalchemy/orm/util.py | 54 ++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 35 deletions(-) (limited to 'lib/sqlalchemy/orm/util.py') diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index c9004990a..49f572572 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -359,15 +359,17 @@ class AliasedClass(object): if isinstance(attr, attributes.QueryableAttribute): return self.__adapt_prop(attr.property) - - if hasattr(attr, 'func_code'): + elif hasattr(attr, 'func_code'): is_method = getattr(self.__target, key, None) if is_method and is_method.im_self is not None: return util.types.MethodType(attr.im_func, self, self) else: return None elif hasattr(attr, '__get__'): - return attr.__get__(None, self) + ret = attr.__get__(None, self) + if isinstance(ret, PropComparator): + return ret.adapted(self.__adapt_element) + return ret else: return attr @@ -536,40 +538,22 @@ def _entity_info(entity, compile=True): return mapper, mapper._with_polymorphic_selectable, False def _entity_descriptor(entity, key): - """Return attribute/property information given an entity and string name. - - Returns a 2-tuple representing InstrumentedAttribute/MapperProperty. + """Return a class attribute given an entity and string name. + + May return :class:`.InstrumentedAttribute` or user-defined + attribute. """ - if isinstance(entity, AliasedClass): - try: - desc = getattr(entity, key) - return desc, desc.property - except AttributeError: - raise sa_exc.InvalidRequestError( - "Entity '%s' has no property '%s'" % - (entity, key) - ) - - elif isinstance(entity, type): - try: - desc = attributes.manager_of_class(entity)[key] - return desc, desc.property - except KeyError: - raise sa_exc.InvalidRequestError( - "Entity '%s' has no property '%s'" % - (entity, key) - ) - - else: - try: - desc = entity.class_manager[key] - return desc, desc.property - except KeyError: - raise sa_exc.InvalidRequestError( - "Entity '%s' has no property '%s'" % - (entity, key) - ) + if not isinstance(entity, (AliasedClass, type)): + entity = entity.class_ + + try: + return getattr(entity, key) + except AttributeError: + raise sa_exc.InvalidRequestError( + "Entity '%s' has no property '%s'" % + (entity, key) + ) def _orm_columns(entity): mapper, selectable, is_aliased_class = _entity_info(entity) -- cgit v1.2.1