From 4c87fb761379348475bcea09a1293eb1dddc6544 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 26 Apr 2010 16:55:11 -0400 Subject: [PATCH] - Fixed regression introduced in 0.6.0 involving improper history accounting on mutable attributes. Essentially reversing r6b2b4fcd4799 and getting it covered. [ticket:1782] --- CHANGES | 4 ++++ lib/sqlalchemy/orm/attributes.py | 3 +-- test/orm/test_unitofwork.py | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 2ae0415a93..9cdae0c81b 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ CHANGES ======= 0.6.1 ===== +- orm + - Fixed regression introduced in 0.6.0 involving improper + history accounting on mutable attributes. [ticket:1782] + - sql - Fixed bug that prevented implicit RETURNING from functioning properly with composite primary key that contained zeroes. diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 5ac8ef9ee4..4390538a02 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -500,8 +500,7 @@ class MutableScalarAttributeImpl(ScalarAttributeImpl): self, state, v) def check_mutable_modified(self, state, dict_): - v = dict_.get(self.key, NO_VALUE) - a, u, d = History.from_attribute(self, state, v) + a, u, d = self.get_history(state, dict_) return bool(a or d) def get(self, state, dict_, passive=PASSIVE_OFF): diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index ba62ce07d1..ea63975178 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -11,7 +11,7 @@ from sqlalchemy.test import engines, testing, pickleable from sqlalchemy import Integer, String, ForeignKey, literal_column from sqlalchemy.test.schema import Table from sqlalchemy.test.schema import Column -from sqlalchemy.orm import mapper, relationship, create_session, column_property +from sqlalchemy.orm import mapper, relationship, create_session, column_property, attributes from sqlalchemy.test.testing import eq_, ne_ from test.orm import _base, _fixtures from test.engine import _base as engine_base @@ -344,6 +344,21 @@ class MutableTypesTest(_base.MappedTest): assert session.query(Foo).one().data == pickleable.Bar(4, 19) + @testing.resolve_artifact_names + def test_resurrect_two(self): + f1 = Foo() + f1.data = pickleable.Bar(4,5) + session = create_session(autocommit=False) + session.add(f1) + session.commit() + + session = create_session(autocommit=False) + f1 = session.query(Foo).first() + del f1 # modified flag flips by accident + gc.collect() + f1 = session.query(Foo).first() + assert not attributes.instance_state(f1).modified + @testing.resolve_artifact_names def test_unicode(self): """Equivalent Unicode values are not flagged as changed.""" -- 2.47.2