]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a check that prevents redundant AttributeImpls from being generated and discarded.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Aug 2010 22:57:33 +0000 (18:57 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Aug 2010 22:57:33 +0000 (18:57 -0400)
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/interfaces.py

index f91ff51f2f7b489e34020dd87f02d6e0dcdc1b43..800f3889f7a6a7402718e0953c0fde8dc921708d 100644 (file)
@@ -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):
index 9874e644fb37e8c4e5b5f075cab3af434d69f496..edd0558ac8dbc5a922dcc5a75437d617a53f11e6 100644 (file)
@@ -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)