]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed bug in mapper refresh/expire whereby eager loaders didnt properly re-populate
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jan 2007 19:33:41 +0000 (19:33 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jan 2007 19:33:41 +0000 (19:33 +0000)
item lists [ticket:407]

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 34c69872a6fae7d66ad4cfe2a7ebfcb00ff6926f..d584564be2d954818e932390927b89809ca757a0 100644 (file)
--- 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"])
index 6c155f2074727266031b17c7fe6b6f996cf51054..1ae8c0be3c5801d3be68d4da79489fe17bf7c1eb 100644 (file)
@@ -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)
index 202bf2111770c1d36ccb8cf40760989c26124a65..146536209bcbc400e84167444d7830f9335b3f87 100644 (file)
@@ -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):