]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix to the fix for [ticket:454], prevent other mappers in a load operation from using...
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 20 Feb 2007 18:01:16 +0000 (18:01 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 20 Feb 2007 18:01:16 +0000 (18:01 +0000)
lib/sqlalchemy/orm/mapper.py
test/orm/mapper.py

index 8c373e1b40562bf6c2734b1673bf2416744fa1a6..9c48682141699830c10562d8770ce12c5a5b28e8 100644 (file)
@@ -1172,7 +1172,15 @@ class Mapper(object):
         either case, executes all the property loaders on the instance to also process extra
         information in the row."""
 
-        ret = context.extension.translate_row(self, context, row)
+        # apply ExtensionOptions applied to the Query to this mapper,
+        # but only if our mapper matches.
+        # TODO: what if our mapper inherits from the mapper (i.e. as in a polymorphic load?)
+        if context.mapper is self:
+            extension = context.extension
+        else:
+            extension = self.extension
+            
+        ret = extension.translate_row(self, context, row)
         if ret is not EXT_PASS:
             row = ret
 
@@ -1202,9 +1210,9 @@ class Mapper(object):
                 if not context.identity_map.has_key(identitykey):
                     context.identity_map[identitykey] = instance
                     isnew = True
-                if context.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
+                if extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
                     self.populate_instance(context, instance, row, identitykey, isnew)
-            if context.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
+            if extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
                 if result is not None:
                     result.append(instance)
             return instance
@@ -1230,7 +1238,7 @@ class Mapper(object):
                         return None
             
             # plugin point
-            instance = context.extension.create_instance(self, context, row, self.class_)
+            instance = extension.create_instance(self, context, row, self.class_)
             if instance is EXT_PASS:
                 instance = self._create_instance(context.session)
             else:
@@ -1245,9 +1253,9 @@ class Mapper(object):
 
         # call further mapper properties on the row, to pull further 
         # instances from the row and possibly populate this item.
-        if context.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
+        if extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
             self.populate_instance(context, instance, row, identitykey, isnew)
-        if context.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
+        if extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
             if result is not None:
                 result.append(instance)
         return instance
index 9189f1f33bba3c369efdeb18a5bd33883dc4fbd2..414aaf378b0c2269ea41cac6133f3a56065d3d89 100644 (file)
@@ -422,7 +422,9 @@ class MapperTest(MapperSuperTest):
                 """test options at the Mapper._instance level"""
                 instance.TEST = "hello world"
                 return EXT_PASS
-        mapper(User, users, extension=ext1())
+        mapper(User, users, extension=ext1(), properties={
+            'addresses':relation(mapper(Address, addresses), lazy=False)
+        })
         class testext(MapperExtension):
             def select_by(self, *args, **kwargs):
                 """test options at the Query level"""
@@ -437,6 +439,11 @@ class MapperTest(MapperSuperTest):
         assert l.user_id == 7
         assert l.TEST == "hello world"
         assert l.TEST_2 == "also hello world"
+        assert not hasattr(l.addresses[0], 'TEST')
+        assert not hasattr(l.addresses[0], 'TEST2')
+        
+        
+        
         
     def testeageroptions(self):
         """tests that a lazy relation can be upgraded to an eager relation via the options method"""