From 28d0b8d1d1b135c2d6974f4d31e56b8d49c8ef09 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 18 Jan 2015 23:32:52 -0500 Subject: [PATCH] - fix another issue from rf49c367ef, add another test --- lib/sqlalchemy/orm/persistence.py | 2 +- test/orm/test_unitofworkv2.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index dbf1d3eb41..d76bb5598b 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -677,7 +677,7 @@ def _emit_update_statements(base_mapper, uowtransaction, c.context.compiled_parameters[0], value_params) - if assert_multirow or assert_singlerow and \ + if hasvalue or assert_multirow or assert_singlerow and \ len(multiparams) == 1: if rows != len(records): raise orm_exc.StaleDataError( diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py index 681b104cff..cef71370d5 100644 --- a/test/orm/test_unitofworkv2.py +++ b/test/orm/test_unitofworkv2.py @@ -5,7 +5,7 @@ from sqlalchemy.testing.schema import Table, Column from test.orm import _fixtures from sqlalchemy import exc, util from sqlalchemy.testing import fixtures, config -from sqlalchemy import Integer, String, ForeignKey, func +from sqlalchemy import Integer, String, ForeignKey, func, literal from sqlalchemy.orm import mapper, relationship, backref, \ create_session, unitofwork, attributes,\ Session, exc as orm_exc @@ -1534,6 +1534,35 @@ class BasicStaleChecksTest(fixtures.MappedTest): [(2, 4)] ) + def test_update_value_missing_broken_multi_rowcount(self): + @util.memoized_property + def rowcount(self): + if len(self.context.compiled_parameters) > 1: + return -1 + else: + return self.context.rowcount + + with patch.object( + config.db.dialect, "supports_sane_multi_rowcount", False): + with patch( + "sqlalchemy.engine.result.ResultProxy.rowcount", + rowcount): + Parent, Child = self._fixture() + sess = Session() + p1 = Parent(id=1, data=1) + sess.add(p1) + sess.flush() + + sess.execute(self.tables.parent.delete()) + + p1.data = literal(1) + assert_raises_message( + orm_exc.StaleDataError, + "UPDATE statement on table 'parent' expected to " + "update 1 row\(s\); 0 were matched.", + sess.flush + ) + @testing.requires.sane_multi_rowcount def test_delete_multi_missing_warning(self): Parent, Child = self._fixture() -- 2.47.3