From: Mike Bayer Date: Sun, 28 Nov 2010 18:45:51 +0000 (-0500) Subject: - a column with a "mutable" type mapped as "deferred" will not X-Git-Tag: rel_0_7b1~227 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94bb2f428e6408c675c306cafb4683c88b48b3dd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - a column with a "mutable" type mapped as "deferred" will not emit a load for the "old" value upon a set event, unless the "active_history" flag is set to True. [ticket:1976] --- diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index d2f5de2b92..97149d97f2 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -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. diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 86f950813d..9ae885bf99 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -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 diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 1411216f22..d8d4afc37e 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -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, diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index d20aada6f3..511adde825 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -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)