From: Mike Bayer Date: Mon, 14 Dec 2015 22:39:50 +0000 (-0500) Subject: - Fixed bug where :meth:`.Session.bulk_update_mappings` and related X-Git-Tag: rel_1_0_11~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf9a53af2e01337373e8ccf6d3d44fcdd55a0b03;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug where :meth:`.Session.bulk_update_mappings` and related would not bump a version id counter when in use. The experience here is still a little rough as the original version id is required in the given dictionaries and there's not clean error reporting on that yet. fixes #3610 (cherry picked from commit 26ed90ab22dde7bdafe933cb1d16acfe70c1ab78) --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 974aa5f1a1..950e2a5d9c 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,17 @@ .. changelog:: :version: 1.0.11 + .. change:: + :tags: bug, orm + :tickets: 3610 + :versions: 1.1.0b1 + + Fixed bug where :meth:`.Session.bulk_update_mappings` and related + would not bump a version id counter when in use. The experience + here is still a little rough as the original version id is required + in the given dictionaries and there's not clean error reporting + on that yet. + .. change:: :tags: bug, sql :tickets: 3609 diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index 35e0920594..c234225dc6 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -490,7 +490,7 @@ def _collect_update_commands( col = mapper.version_id_col params[col._label] = update_version_id - if col.key not in params and \ + if (bulk or col.key not in params) and \ mapper.version_id_generator is not False: val = mapper.version_id_generator(update_version_id) params[col.key] = val diff --git a/test/orm/test_versioning.py b/test/orm/test_versioning.py index 124053d470..07b090c60d 100644 --- a/test/orm/test_versioning.py +++ b/test/orm/test_versioning.py @@ -130,6 +130,43 @@ class VersioningTest(fixtures.MappedTest): [(f1.id, 'f1rev2', 2), (f2.id, 'f2rev2', 2)] ) + def test_bulk_insert(self): + Foo = self.classes.Foo + + s1 = self._fixture() + s1.bulk_insert_mappings( + Foo, + [{"id": 1, "value": "f1"}, {"id": 2, "value": "f2"}] + ) + eq_( + s1.query(Foo.id, Foo.value, Foo.version_id).order_by(Foo.id).all(), + [(1, 'f1', 1), (2, 'f2', 1)] + ) + + def test_bulk_update(self): + Foo = self.classes.Foo + + s1 = self._fixture() + f1 = Foo(value='f1') + f2 = Foo(value='f2') + s1.add_all((f1, f2)) + s1.commit() + + s1.bulk_update_mappings( + Foo, + [ + {"id": f1.id, "value": "f1rev2", "version_id": 1}, + {"id": f2.id, "value": "f2rev2", "version_id": 1}, + + ] + ) + s1.commit() + + eq_( + s1.query(Foo.id, Foo.value, Foo.version_id).order_by(Foo.id).all(), + [(f1.id, 'f1rev2', 2), (f2.id, 'f2rev2', 2)] + ) + @testing.emits_warning_on( '+zxjdbc', r'.*does not support (update|delete)d rowcount') def test_bump_version(self):