mutable types + deferred, may be able to skip the load

Issue #1976 resolved
Mike Bayer repo owner created an issue

ironically this affects the "active_history" flag we thought we didn't need in #1961.

All tests pass (except for the active history one) with:

diff -r e15fa0342d2ac83414c563abd8fd478251d4d35f lib/sqlalchemy/orm/attributes.py
--- a/lib/sqlalchemy/orm/attributes.py  Thu Nov 18 20:12:24 2010 -0500
+++ b/lib/sqlalchemy/orm/attributes.py  Fri Nov 19 14:50:53 2010 -0500
@@ -531,16 +531,7 @@
         state.mutable_dict.pop(self.key)

     def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
-        if initiator and initiator.parent_token is self.parent_token:
-            return
-
-        if self.extensions:
-            old = self.get(state, dict_)
-            value = self.fire_replace_event(state, dict_, 
-                                            value, old, initiator)
-
-        state.modified_event(dict_, self, True, NEVER_SET)
-        dict_[self.key](self.key) = value
+        ScalarAttributeImpl.set(self, state, dict_, value, initiator, passive)
         state.mutable_dict[self.key](self.key) = value


diff -r e15fa0342d2ac83414c563abd8fd478251d4d35f test/orm/test_unitofwork.py
--- a/test/orm/test_unitofwork.py   Thu Nov 18 20:12:24 2010 -0500
+++ b/test/orm/test_unitofwork.py   Fri Nov 19 14:50:53 2010 -0500
@@ -393,7 +393,29 @@
         f1 = session.query(Foo).get(f1.id)
         f1.val = u'hi'
         self.sql_count_(0, session.commit)
-
+    
+    @testing.resolve_artifact_names
+    def test_deferred(self):
+        sa.orm.clear_mappers()
+        mapper(Foo, mutable_t, properties={
+            'data':sa.orm.deferred(mutable_t.c.data)
+        })
+
+        f1 = Foo(data = pickleable.Bar(4, 5), val=u'some val')
+        session = Session()
+        session.add(f1)
+        session.commit()
+        
+        session.close()
+        
+        f1 = session.query(Foo).first()
+        print "1----------------"
+        f1.data = pickleable.Bar(10, 15)
+        print "2----------------"
+        session.commit()
+        
+        eq_(f1.data.x, 10)
+

 class PickledDictsTest(_base.MappedTest):

consider targeting this at 0.7 to reduce risk.

Comments (3)

  1. Log in to comment