summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-03-28 18:00:35 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-03-28 18:00:35 -0400
commitd6618e41195587291c4a82af0db43fbd993b6c77 (patch)
treea93e608f2a145621ef19dfc869b78806e9b2f5bd /test
parenta0329f71ad48b16ad9dad44d5a5cb2c920e569f1 (diff)
downloadsqlalchemy-d6618e41195587291c4a82af0db43fbd993b6c77.tar.gz
- Added new parameter :paramref:`.mapper.confirm_deleted_rows`. Defaults
to True, indicates that a series of DELETE statements should confirm that the cursor rowcount matches the number of primary keys that should have matched; this behavior had been taken off in most cases (except when version_id is used) to support the unusual edge case of self-referential ON DELETE CASCADE; to accomodate this, the message is now just a warning, not an exception, and the flag can be used to indicate a mapping that expects self-refererntial cascaded deletes of this nature. See also :ticket:`2403` for background on the original change. re: #2403 fix #3007
Diffstat (limited to 'test')
-rw-r--r--test/orm/test_unitofwork.py1
-rw-r--r--test/orm/test_unitofworkv2.py36
2 files changed, 25 insertions, 12 deletions
diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py
index 61f736ce6..4776e2988 100644
--- a/test/orm/test_unitofwork.py
+++ b/test/orm/test_unitofwork.py
@@ -562,6 +562,7 @@ class BatchDeleteIgnoresRowcountTest(fixtures.DeclarativeMappedTest):
class A(cls.DeclarativeBasic):
__tablename__ = 'A'
__table_args__ = dict(test_needs_fk=True)
+ __mapper_args__ = {"confirm_deleted_rows": False}
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('A.id', ondelete='CASCADE'))
diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py
index 0ac3349af..5512535e5 100644
--- a/test/orm/test_unitofworkv2.py
+++ b/test/orm/test_unitofworkv2.py
@@ -3,6 +3,7 @@ from sqlalchemy import testing
from sqlalchemy.testing import engines
from sqlalchemy.testing.schema import Table, Column
from test.orm import _fixtures
+from sqlalchemy import exc
from sqlalchemy.testing import fixtures
from sqlalchemy import Integer, String, ForeignKey, func
from sqlalchemy.orm import mapper, relationship, backref, \
@@ -1284,7 +1285,7 @@ class BasicStaleChecksTest(fixtures.MappedTest):
Column('data', Integer)
)
- def _fixture(self):
+ def _fixture(self, confirm_deleted_rows=True):
parent, child = self.tables.parent, self.tables.child
class Parent(fixtures.BasicEntity):
@@ -1295,8 +1296,8 @@ class BasicStaleChecksTest(fixtures.MappedTest):
mapper(Parent, parent, properties={
'child':relationship(Child, uselist=False,
cascade="all, delete-orphan",
- backref="parent")
- })
+ backref="parent"),
+ }, confirm_deleted_rows=confirm_deleted_rows)
mapper(Child, child)
return Parent, Child
@@ -1318,7 +1319,7 @@ class BasicStaleChecksTest(fixtures.MappedTest):
)
@testing.requires.sane_multi_rowcount
- def test_delete_multi_missing(self):
+ def test_delete_multi_missing_warning(self):
Parent, Child = self._fixture()
sess = Session()
p1 = Parent(id=1, data=2, child=None)
@@ -1330,16 +1331,27 @@ class BasicStaleChecksTest(fixtures.MappedTest):
sess.delete(p1)
sess.delete(p2)
+ assert_raises_message(
+ exc.SAWarning,
+ "DELETE statement on table 'parent' expected to "
+ "delete 2 row\(s\); 0 were matched.",
+ sess.flush
+ )
+
+ @testing.requires.sane_multi_rowcount
+ def test_delete_multi_missing_allow(self):
+ Parent, Child = self._fixture(confirm_deleted_rows=False)
+ sess = Session()
+ p1 = Parent(id=1, data=2, child=None)
+ p2 = Parent(id=2, data=3, child=None)
+ sess.add_all([p1, p2])
sess.flush()
- # see issue #2403 - we *cannot* use rowcount here, as
- # self-referential DELETE CASCADE could have deleted rows
- #assert_raises_message(
- # orm_exc.StaleDataError,
- # "DELETE statement on table 'parent' expected to "
- # "delete 2 row\(s\); 0 were matched.",
- # sess.flush
- #)
+ sess.execute(self.tables.parent.delete())
+ sess.delete(p1)
+ sess.delete(p2)
+
+ sess.flush()
class BatchInsertsTest(fixtures.MappedTest, testing.AssertsExecutionResults):