1. idank
  2. sqlalchemy

Commits

Mike Bayer  committed 6821e86

mass load wont overwrite modified expired attributes

  • Participants
  • Parent commits c62aadb
  • Branches default

Comments (0)

Files changed (3)

File lib/sqlalchemy/orm/attributes.py

View file
         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()

File lib/sqlalchemy/orm/mapper.py

View file
                 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)

File test/orm/expire.py

View file
 
         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)