From: Mike Bayer Date: Tue, 20 Feb 2007 18:01:16 +0000 (+0000) Subject: fix to the fix for [ticket:454], prevent other mappers in a load operation from using... X-Git-Tag: rel_0_3_5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd2f52a7e30084c78a4f19742ee0749a912aafe3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix to the fix for [ticket:454], prevent other mappers in a load operation from using the main extension option send to the query (i.e. mappers used for eager loads etc). --- diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 8c373e1b40..9c48682141 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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 diff --git a/test/orm/mapper.py b/test/orm/mapper.py index 9189f1f33b..414aaf378b 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -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"""