From 6f131f00c60e477942dbadec344bd1cf14c69ff2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 2 Jan 2007 19:33:41 +0000 Subject: [PATCH] - fixed bug in mapper refresh/expire whereby eager loaders didnt properly re-populate item lists [ticket:407] --- CHANGES | 2 ++ lib/sqlalchemy/orm/mapper.py | 5 +++-- test/orm/mapper.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 34c69872a6..d584564be2 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,8 @@ largely interchangeable with "ensure" (so says the dictionary), so I'm not completely illiterate, but its definitely sub-optimal to "ensure" which is non-ambiguous. - invalid options sent to 'cascade' string will raise an exception [ticket:406] +- fixed bug in mapper refresh/expire whereby eager loaders didnt properly re-populate +item lists [ticket:407] 0.3.3 - string-based FROM clauses fixed, i.e. select(..., from_obj=["sometext"]) diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 6c155f2074..1ae8c0be3c 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1156,8 +1156,9 @@ class Mapper(object): if populate_existing or context.session.is_expired(instance, unexpire=True): if not context.identity_map.has_key(identitykey): context.identity_map[identitykey] = instance - if self.extension.populate_instance(self, context, row, instance, identitykey, True) is EXT_PASS: - self.populate_instance(context, instance, row, identitykey, True) + isnew = True + if self.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS: + self.populate_instance(context, instance, row, identitykey, isnew) if self.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS: if result is not None: result.append(instance) diff --git a/test/orm/mapper.py b/test/orm/mapper.py index 202bf21117..146536209b 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -113,7 +113,22 @@ class MapperTest(MapperSuperTest): # get the attribute, it refreshes self.assert_(u.user_name == 'jack') self.assert_(a not in u.addresses) + + def testrefreshwitheager(self): + """test that a refresh/expire operation loads rows properly and sends correct "isnew" state to eager loaders""" + mapper(User, users, properties={'addresses':relation(mapper(Address, addresses), lazy=False)}) + s = create_session() + u = s.get(User, 8) + assert len(u.addresses) == 3 + s.refresh(u) + assert len(u.addresses) == 3 + s = create_session() + u = s.get(User, 8) + assert len(u.addresses) == 3 + s.expire(u) + assert len(u.addresses) == 3 + def testbadconstructor(self): """test that if the construction of a mapped class fails, the instnace does not get placed in the session""" class Foo(object): -- 2.47.2