From: Mike Bayer Date: Sun, 16 Dec 2007 20:32:56 +0000 (+0000) Subject: fixed del history X-Git-Tag: rel_0_4_2~36 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=420c098d56e9925b51067711c6817475165c6af2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fixed del history --- diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 4f10ecc225..677167c1b9 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -256,6 +256,9 @@ class ScalarAttributeImpl(AttributeImpl): accepts_global_callable = True def delete(self, state): + if self.key not in state.committed_state: + state.committed_state[self.key] = state.dict.get(self.key, NO_VALUE) + del state.dict[self.key] state.modified=True @@ -968,7 +971,11 @@ def _create_history(attr, state, current): return (list(collection.difference(s)), list(collection.intersection(s)), list(s.difference(collection))) else: if current is NO_VALUE: - return ([], [], []) + if original not in [None, NEVER_SET, NO_VALUE]: + deleted = [original] + else: + deleted = [] + return ([], [], deleted) elif original is NO_VALUE: return ([current], [], []) elif original is NEVER_SET or attr.is_equal(current, original) is True: # dont let ClauseElement expressions here trip things up diff --git a/test/orm/attributes.py b/test/orm/attributes.py index 96940ec205..088e336237 100644 --- a/test/orm/attributes.py +++ b/test/orm/attributes.py @@ -540,6 +540,9 @@ class HistoryTest(PersistTest): self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], ['there'], [])) + del f.someattr + self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], [], ['there'])) + # case 2. object with direct dictionary settings (similar to a load operation) f = Foo() f.__dict__['someattr'] = 'new' @@ -626,6 +629,9 @@ class HistoryTest(PersistTest): self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], ['there'], [])) + del f.someattr + self.assertEquals(attributes.get_history(f._state, 'someattr'), ([None], [], ['there'])) + # case 2. object with direct dictionary settings (similar to a load operation) f = Foo() f.__dict__['someattr'] = 'new'