]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix regression from 0.7 where calling get_history with passive
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Oct 2012 17:54:39 +0000 (13:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Oct 2012 17:54:39 +0000 (13:54 -0400)
on a never-set collection would fail; made this act just like
scalars for now and added tests.  I would think that HISTORY_BLANK
would be more appropriate here but it's too late in the game
to mess with that.

lib/sqlalchemy/orm/attributes.py
test/orm/test_attributes.py

index eec72b5f3350809fa24e58930df800239e849f1a..86da9a61d1c4c1baf3ba7ef46d98ededd5c6975c 100644 (file)
@@ -1216,6 +1216,10 @@ class History(History):
     @classmethod
     def from_collection(cls, attribute, state, current):
         original = state.committed_state.get(attribute.key, _NO_HISTORY)
+
+        if current is NO_VALUE or current is NEVER_SET:
+            return cls((), (), ())
+
         current = getattr(current, '_sa_adapter')
         if original is NO_VALUE:
             return cls(list(current), (), ())
index 46b1a6c3b093acb59c242738258f88b38c89e953..1fc70fd77b63fed7d925d9191a6c2b095e4c4994 100644 (file)
@@ -1382,10 +1382,10 @@ class HistoryTest(fixtures.TestBase):
                 useobject=True)
         return Foo, Bar
 
-    def _someattr_history(self, f):
+    def _someattr_history(self, f, **kw):
         return attributes.get_state_history(
                     attributes.instance_state(f),
-                    'someattr')
+                    'someattr', **kw)
 
     def _commit_someattr(self, f):
         attributes.instance_state(f)._commit(attributes.instance_dict(f),
@@ -1553,6 +1553,24 @@ class HistoryTest(fixtures.TestBase):
         assert 'someattr' not in f.__dict__
         assert 'someattr' not in attributes.instance_state(f).committed_state
 
+    def test_collection_never_set(self):
+        Foo = self._fixture(uselist=True, useobject=True,
+                                active_history=True)
+        f = Foo()
+        eq_(self._someattr_history(f, passive=True), ((), (), ()))
+
+    def test_scalar_obj_never_set(self):
+        Foo = self._fixture(uselist=False, useobject=True,
+                                active_history=True)
+        f = Foo()
+        eq_(self._someattr_history(f, passive=True), ((), (), ()))
+
+    def test_scalar_never_set(self):
+        Foo = self._fixture(uselist=False, useobject=False,
+                                active_history=True)
+        f = Foo()
+        eq_(self._someattr_history(f, passive=True), ((), (), ()))
+
     def test_scalar_active_set(self):
         Foo = self._fixture(uselist=False, useobject=False,
                                 active_history=True)