]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
mass load wont overwrite modified expired attributes
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Dec 2007 07:26:39 +0000 (07:26 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Dec 2007 07:26:39 +0000 (07:26 +0000)
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/mapper.py
test/orm/expire.py

index 135269906bd23969ce48758ac6e59784563de077..f18e54521f6fbef3ca0b0b1339787457f33475dd 100644 (file)
@@ -766,7 +766,7 @@ class InstanceState(object):
         serializable.
         """
         instance = self.obj()
-        self.class_._class_state.deferred_scalar_loader(instance, [k for k in self.expired_attributes if k not in self.committed_state])
+        self.class_._class_state.deferred_scalar_loader(instance, [k for k in self.expired_attributes if k in self.unmodified])
         for k in self.expired_attributes:
             self.callables.pop(k, None)
         self.expired_attributes.clear()
index db666a4f99e0991aa37def7f9640581a19a187e2..f61b70bc3c860076221be4459ae57dbe943d53ed 100644 (file)
@@ -1367,8 +1367,11 @@ class Mapper(object):
                 self.populate_instance(context, instance, row, only_load_props=only_load_props, instancekey=identitykey, isnew=isnew)
 
         elif getattr(state, 'expired_attributes', None):
-            if 'populate_instance' not in extension.methods or extension.populate_instance(self, context, row, instance, only_load_props=state.expired_attributes, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE:
-                self.populate_instance(context, instance, row, only_load_props=state.expired_attributes, instancekey=identitykey, isnew=isnew)
+            # TODO: dont base this off of 'expired_attrbutes' - base it off of unloaded attrs, possibly
+            # based on the state.callables collection.  
+            attrs = state.expired_attributes.intersection(state.unmodified)
+            if 'populate_instance' not in extension.methods or extension.populate_instance(self, context, row, instance, only_load_props=attrs, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE:
+                self.populate_instance(context, instance, row, only_load_props=attrs, instancekey=identitykey, isnew=isnew)
             
         if result is not None and ('append_result' not in extension.methods or extension.append_result(self, context, row, instance, result, instancekey=identitykey, isnew=isnew) is EXT_CONTINUE):
             result.append(instance)
index e1c0166120e7b845be0ee444bed76c61ec6de58a..1b6e0affd17325282a9b8e49ef0bad4b04b0f719 100644 (file)
@@ -84,6 +84,20 @@ class ExpireTest(FixtureTest):
 
         assert o.description is None
         
+        o.isopen=15
+        sess.expire(o, ['isopen', 'description'])
+        o.description = 'some new description'
+        sess.query(Order).all()
+        assert o.isopen == 1
+        assert o.description == 'some new description'
+        
+        sess.expire(o, ['isopen', 'description'])
+        sess.query(Order).all()
+        del o.isopen
+        def go():
+            assert o.isopen is None
+        self.assert_sql_count(testbase.db, go, 0)
+        
     def test_expire_committed(self):
         """test that the committed state of the attribute receives the most recent DB data"""
         mapper(Order, orders)