]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where :meth:`.Session.bulk_update_mappings` and related
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Dec 2015 22:39:50 +0000 (17:39 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Dec 2015 22:39:50 +0000 (17:39 -0500)
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

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/persistence.py
test/orm/test_versioning.py

index 974aa5f1a1f3d53af5ab8f7b5ba0cd0bf3530d95..950e2a5d9ce35f51df62124e4888aa72756c1fbe 100644 (file)
 .. 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
index 88c96e94ce169387f5561ea2a2f5e0b4614b9fa8..77c513aef4d74d09fb30e36024dfbb169ab54ea7 100644 (file)
@@ -492,7 +492,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
index 124053d4709a27b8f248636962738775a5e71daf..07b090c60de91f6622dcc24f8788b82f844e712d 100644 (file)
@@ -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):