From cea9cc5e8eb17e9ddee160bf5cfa29c438ef42df Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 18 Jun 2009 19:37:16 +0000 Subject: [PATCH] - repaired non-working attributes.set_committed_value function. --- CHANGES | 2 ++ lib/sqlalchemy/orm/attributes.py | 2 +- test/orm/test_attributes.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 1d986020a2..4f814d4bcf 100644 --- a/CHANGES +++ b/CHANGES @@ -45,6 +45,8 @@ CHANGES columns, has been enhanced such that the fk->itself aspect of the relation won't be used to determine relation direction. + - repaired non-working attributes.set_committed_value function. + - Trimmed the pickle format for InstanceState which should further reduce the memory footprint of pickled instances. The format should be backwards compatible with that of 0.5.4 and previous. diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 4fe562110d..2c26f34f2a 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1418,7 +1418,7 @@ def set_committed_value(instance, key, value): """ state, dict_ = instance_state(instance), instance_dict(instance) - state.get_impl(key).set_committed_value(state, dict_, key, value) + state.get_impl(key).set_committed_value(state, dict_, value) def set_attribute(instance, key, value): """Set the value of an attribute, firing history events. diff --git a/test/orm/test_attributes.py b/test/orm/test_attributes.py index 3b1b42dadc..ca8cef3ad8 100644 --- a/test/orm/test_attributes.py +++ b/test/orm/test_attributes.py @@ -512,6 +512,32 @@ class AttributesTest(_base.ORMTest): except sa_exc.ArgumentError, e: assert False +class UtilTest(_base.ORMTest): + def test_helpers(self): + class Foo(object): + pass + + class Bar(object): + pass + + attributes.register_class(Foo) + attributes.register_class(Bar) + attributes.register_attribute(Foo, "coll", uselist=True, useobject=True) + + f1 = Foo() + b1 = Bar() + b2 = Bar() + coll = attributes.init_collection(f1, "coll") + assert coll.data is f1.coll + assert attributes.get_attribute(f1, "coll") is f1.coll + attributes.set_attribute(f1, "coll", [b1]) + assert f1.coll == [b1] + eq_(attributes.get_history(f1, "coll"), ([b1], [], [])) + attributes.set_committed_value(f1, "coll", [b2]) + eq_(attributes.get_history(f1, "coll"), ((), [b2], ())) + + attributes.del_attribute(f1, "coll") + assert "coll" not in f1.__dict__ class BackrefTest(_base.ORMTest): -- 2.47.2