summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-03 18:07:06 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-06 17:29:04 -0400
commitaa94afcdaf4faeacf13836de2475954e06a7fb67 (patch)
tree66fd5e9625d424806bd8e2f656669a686404e343
parent1c3e92627362604472ca483055fc827a97942e6b (diff)
downloadsqlalchemy-aa94afcdaf4faeacf13836de2475954e06a7fb67.tar.gz
Don't warn on multi delete rowcount if supports_sane_multi is False
Fixed an issue where the "number of rows matched" warning would emit even if the dialect reported "supports_sane_multi_rowcount=False", as is the case for psycogp2 with ``use_batch_mode=True`` and others. Fixes: #4661 Change-Id: I93aaf7f597b6083e860ab3cbcd620ba5621c57a8
-rw-r--r--doc/build/changelog/unreleased_13/4661.rst8
-rw-r--r--lib/sqlalchemy/orm/persistence.py1
-rw-r--r--test/orm/test_unitofworkv2.py18
3 files changed, 27 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_13/4661.rst b/doc/build/changelog/unreleased_13/4661.rst
new file mode 100644
index 000000000..f3b1b58ca
--- /dev/null
+++ b/doc/build/changelog/unreleased_13/4661.rst
@@ -0,0 +1,8 @@
+.. change::
+ :tags: bug, postgresql, orm
+ :tickets: 4661
+
+ Fixed an issue where the "number of rows matched" warning would emit even if
+ the dialect reported "supports_sane_multi_rowcount=False", as is the case
+ for psycogp2 with ``use_batch_mode=True`` and others.
+
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index 6345ee28a..e9e6975ca 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -1335,6 +1335,7 @@ def _emit_delete_statements(
if (
base_mapper.confirm_deleted_rows
+ and connection.dialect.supports_sane_multi_rowcount
and rows_matched > -1
and expected != rows_matched
):
diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py
index 9d7879bb2..fdb50f37d 100644
--- a/test/orm/test_unitofworkv2.py
+++ b/test/orm/test_unitofworkv2.py
@@ -1758,6 +1758,24 @@ class BasicStaleChecksTest(fixtures.MappedTest):
sess.flush,
)
+ def test_delete_multi_broken_multi_rowcount(self):
+ Parent, Child = self._fixture()
+ 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()
+
+ sess.execute(self.tables.parent.delete())
+ sess.delete(p1)
+ sess.delete(p2)
+
+ with patch.object(
+ config.db.dialect, "supports_sane_multi_rowcount", False
+ ):
+ # no warning
+ sess.flush()
+
def test_delete_multi_missing_allow(self):
Parent, Child = self._fixture(confirm_deleted_rows=False)
sess = Session()