summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-10 22:36:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-10 22:36:40 -0400
commitbdafff8982d9e7fbf9a39182f1fb8e65d475bbb9 (patch)
tree6b4f5d10dc420bada9e8e007fb677f21e32008ed /lib/sqlalchemy/orm
parentf601791a914d3181252493800871c458ad6c46d1 (diff)
downloadsqlalchemy-bdafff8982d9e7fbf9a39182f1fb8e65d475bbb9.tar.gz
Correct fix and tests for #4661
For #4661 we need to still warn if we are only deleting one row, even if sane multi rowcount is false. Tests were failing for pyodbc since the warning was removed for the single-row case. the UPDATE logic raises if a single row doesn't match even if sane multi rowcount is false, so this is now more consistent with that. Add tests for the UPDATE case also. It is possible there are already tests for this but as the DELETE case wasn't well covered it's not clear. Fixes: #4661 Change-Id: Ie57f765ff31bf806206837c5fbfe449b02ebf4be
Diffstat (limited to 'lib/sqlalchemy/orm')
-rw-r--r--lib/sqlalchemy/orm/persistence.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index e9e6975ca..f1a73c7cd 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -1301,15 +1301,11 @@ def _emit_delete_statements(
expected = len(del_objects)
rows_matched = -1
only_warn = False
- if connection.dialect.supports_sane_multi_rowcount:
- c = connection.execute(statement, del_objects)
-
- if not need_version_id:
- only_warn = True
-
- rows_matched = c.rowcount
- elif need_version_id:
+ if (
+ need_version_id
+ and not connection.dialect.supports_sane_multi_rowcount
+ ):
if connection.dialect.supports_sane_rowcount:
rows_matched = 0
# execute deletes individually so that versioned
@@ -1335,10 +1331,15 @@ 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
+ and (
+ connection.dialect.supports_sane_multi_rowcount
+ or len(del_objects) == 1
+ )
):
+ # TODO: why does this "only warn" if versioning is turned off,
+ # whereas the UPDATE raises?
if only_warn:
util.warn(
"DELETE statement on table '%s' expected to "