diff options
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 4 | ||||
| -rw-r--r-- | test/orm/test_attributes.py | 22 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index eec72b5f3..86da9a61d 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -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), (), ()) diff --git a/test/orm/test_attributes.py b/test/orm/test_attributes.py index 46b1a6c3b..1fc70fd77 100644 --- a/test/orm/test_attributes.py +++ b/test/orm/test_attributes.py @@ -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) |
