From: Mike Bayer Date: Sun, 8 Aug 2010 22:57:33 +0000 (-0400) Subject: - add a check that prevents redundant AttributeImpls from being generated and discarded. X-Git-Tag: rel_0_6_4~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99713acd79b0cbaebb0d09050e5c6c2fba05b3eb;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add a check that prevents redundant AttributeImpls from being generated and discarded. --- diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index f91ff51f2f..800f3889f7 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -299,6 +299,7 @@ class AttributeImpl(object): self.active_history = active_history self.expire_missing = expire_missing + def hasparent(self, state, optimistic=False): """Return the boolean value of a `hasparent` flag attached to the given state. @@ -965,6 +966,14 @@ class ClassManager(dict): def mapper(self): raise exc.UnmappedClassError(self.class_) + def _attr_has_impl(self, key): + """Return True if the given attribute is fully initialized. + + i.e. has an impl. + """ + + return key in self and self[key].impl is not None + def _configure_create_arguments(self, _source=None, deferred_scalar_loader=None): @@ -1456,6 +1465,7 @@ def register_attribute_impl(class_, key, manager[key].impl = impl manager.post_configure_attribute(key) + def register_descriptor(class_, key, proxy_property=None, comparator=None, parententity=None, property_=None, doc=None): diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 9874e644fb..edd0558ac8 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -482,7 +482,7 @@ class MapperProperty(object): _compile_started = False _compile_finished = False - + def init(self): """Called after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation @@ -647,7 +647,7 @@ class StrategizedProperty(MapperProperty): ``StrategizedOption`` objects via the Query.options() method. """ - + def _get_context_strategy(self, context, path): cls = context.attributes.get(('loaderstrategy', _reduce_path(path)), None) @@ -683,9 +683,10 @@ class StrategizedProperty(MapperProperty): self.strategy = self.__init_strategy(self.strategy_class) def post_instrument_class(self, mapper): - if self.is_primary(): + if self.is_primary() and \ + not mapper.class_manager._attr_has_impl(self.key): self.strategy.init_class_attribute(mapper) - + def build_path(entity, key, prev=None): if prev: return prev + (entity, key)