]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixed del history
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 16 Dec 2007 20:32:56 +0000 (20:32 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 16 Dec 2007 20:32:56 +0000 (20:32 +0000)
lib/sqlalchemy/orm/attributes.py
test/orm/attributes.py

index 4f10ecc2254d0065cb73c8663b0ebe90f84a246a..677167c1b9edd42860a426651a00be2e14fd4e97 100644 (file)
@@ -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
index 96940ec205410c732f165f89ca77cac617dbf157..088e33623716cf1fc6321aa6c5d6789c38d95e67 100644 (file)
@@ -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'