From: Mike Bayer Date: Fri, 3 May 2019 22:07:06 +0000 (-0400) Subject: Don't warn on multi delete rowcount if supports_sane_multi is False X-Git-Tag: rel_1_3_4~23^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c4ba0e8ff299031d24e9cd1f4aea654e064f934;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 (cherry picked from commit aa94afcdaf4faeacf13836de2475954e06a7fb67) --- diff --git a/doc/build/changelog/unreleased_13/4661.rst b/doc/build/changelog/unreleased_13/4661.rst new file mode 100644 index 0000000000..f3b1b58ca7 --- /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 6345ee28a5..e9e6975ca3 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 9d7879bb24..fdb50f37db 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()