summaryrefslogtreecommitdiff
path: root/test/orm
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-03-21 17:11:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-21 17:35:12 -0400
commit711d29f8e4dc096f5083c075a1f64eb38e2d2e4a (patch)
treefe28b0e8f708dc6605ac19062594ff831fb95651 /test/orm
parentcaeb274e287f514a50524fc9fe4aeedcb3740147 (diff)
downloadsqlalchemy-711d29f8e4dc096f5083c075a1f64eb38e2d2e4a.tar.gz
Raise on flag_modified() for non-present attribute
The :func:`.attributes.flag_modified` function now raises :class:`.InvalidRequestError` if the named attribute key is not present within the object, as this is assumed to be present in the flush process. To mark an object "dirty" for a flush without referring to any specific attribute, the :func:`.attributes.flag_dirty` function may be used. Change-Id: I6c64e4d253c239e38632f38c27bb16e68fe8dfbe Fixes: #3753
Diffstat (limited to 'test/orm')
-rw-r--r--test/orm/test_attributes.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/test/orm/test_attributes.py b/test/orm/test_attributes.py
index d3a63c386..6dcba1f3f 100644
--- a/test/orm/test_attributes.py
+++ b/test/orm/test_attributes.py
@@ -4,7 +4,7 @@ from sqlalchemy.orm.collections import collection
from sqlalchemy.orm.interfaces import AttributeExtension
from sqlalchemy import exc as sa_exc
from sqlalchemy.testing import eq_, ne_, assert_raises, \
- assert_raises_message
+ assert_raises_message, is_true, is_false
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.util import gc_collect, all_partial_orderings
from sqlalchemy.util import jython
@@ -1963,6 +1963,43 @@ class HistoryTest(fixtures.TestBase):
attributes.flag_modified(f, 'someattr')
eq_(self._someattr_history(f), ([{'a': 'b'}], (), ()))
+ def test_flag_modified_but_no_value_raises(self):
+ Foo = self._fixture(uselist=False, useobject=False,
+ active_history=False)
+ f = Foo()
+ f.someattr = 'foo'
+ self._commit_someattr(f)
+ eq_(self._someattr_history(f), ((), ['foo'], ()))
+
+ attributes.instance_state(f)._expire_attributes(
+ attributes.instance_dict(f),
+ ['someattr'])
+
+ assert_raises_message(
+ sa_exc.InvalidRequestError,
+ "Can't flag attribute 'someattr' modified; it's "
+ "not present in the object state",
+ attributes.flag_modified, f, 'someattr'
+ )
+
+ def test_mark_dirty_no_attr(self):
+ Foo = self._fixture(uselist=False, useobject=False,
+ active_history=False)
+ f = Foo()
+ f.someattr = 'foo'
+ attributes.instance_state(f)._commit_all(f.__dict__)
+ eq_(self._someattr_history(f), ((), ['foo'], ()))
+
+ attributes.instance_state(f)._expire_attributes(
+ attributes.instance_dict(f),
+ ['someattr'])
+
+ is_false(attributes.instance_state(f).modified)
+
+ attributes.flag_dirty(f)
+
+ is_true(attributes.instance_state(f).modified)
+
def test_use_object_init(self):
Foo, Bar = self._two_obj_fixture(uselist=False)
f = Foo()