]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- a column with a "mutable" type mapped as "deferred" will not
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Nov 2010 18:45:51 +0000 (13:45 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 Nov 2010 18:45:51 +0000 (13:45 -0500)
emit a load for the "old" value upon a set event,
unless the "active_history" flag is set to True.  [ticket:1976]

lib/sqlalchemy/orm/__init__.py
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/strategies.py
test/orm/test_unitofwork.py

index d2f5de2b92866f88fef6478f3f222ed10a043bec..97149d97f2e50d51132e02722017cc1ee19dbc03 100644 (file)
@@ -651,11 +651,9 @@ def composite(class_, *cols, **kwargs):
     :param active_history=False:
       When ``True``, indicates that the "previous" value for a
       scalar attribute should be loaded when replaced, if not
-      already loaded.  Note that attributes generated by 
-      :func:`.composite` properties load the "previous" value
-      in any case, however this is being changed in 0.7, 
-      so the flag is introduced here for forwards compatibility.
-      (new in 0.6.6)
+      already loaded.  See the same flag on :func:`.column_property`.
+      (This flag becomes meaningful specifically for 
+      :func:`.composite` in 0.7 - previously it was a placeholder).
 
     :param group:
       A group name for this property when marked as deferred.
index 86f950813d9aeb1d8474f084813f47ee854d586a..9ae885bf9930b1cfb859ba3b2077a055a671a865 100644 (file)
@@ -488,16 +488,7 @@ class MutableScalarAttributeImpl(ScalarAttributeImpl):
         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.dispatch.on_set:
-            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] = value
+        ScalarAttributeImpl.set(self, state, dict_, value, initiator, passive)
         state.mutable_dict[self.key] = value
 
 
index 1411216f22e4ae7cadb1aafe4804ad103414a9e5..d8d4afc37e11ec56a725d42b8ef2697d18d7993c 100644 (file)
@@ -166,6 +166,7 @@ class CompositeColumnLoader(ColumnLoader):
             compare_function=compare,
             copy_function=copy,
             mutable_scalars=True,
+            active_history=self.parent_property.active_history,
         )
 
     def create_row_processor(self, selectcontext, path, mapper, 
index d20aada6f3757876777c68830c853e7a4b08566e..511adde825b494fec036e28f1a3c7e7ca1070954 100644 (file)
@@ -410,8 +410,8 @@ class MutableTypesTest(_base.MappedTest):
 
     @testing.resolve_artifact_names
     def test_expire_attribute_set(self):
-        """test one SELECT emitted when assigning to an expired
-        mutable attribute - this will become 0 in 0.7.
+        """test no SELECT emitted when assigning to an expired
+        mutable attribute.
         
         """
         
@@ -423,7 +423,7 @@ class MutableTypesTest(_base.MappedTest):
         assert 'data' not in f1.__dict__
         def go():
             f1.data = pickleable.Bar(10, 15)
-        self.sql_count_(1, go)
+        self.sql_count_(0, go)
         session.commit()
         
         eq_(f1.data.x, 10)
@@ -448,8 +448,8 @@ class MutableTypesTest(_base.MappedTest):
         
     @testing.resolve_artifact_names
     def test_deferred_attribute_set(self):
-        """test one SELECT emitted when assigning to a deferred
-        mutable attribute - this will become 0 in 0.7.
+        """test no SELECT emitted when assigning to a deferred
+        mutable attribute.
         
         """
         sa.orm.clear_mappers()
@@ -467,7 +467,7 @@ class MutableTypesTest(_base.MappedTest):
         f1 = session.query(Foo).first()
         def go():
             f1.data = pickleable.Bar(10, 15)
-        self.sql_count_(1, go)
+        self.sql_count_(0, go)
         session.commit()
         
         eq_(f1.data.x, 10)