summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-12-14 17:39:50 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-12-14 17:39:50 -0500
commit26ed90ab22dde7bdafe933cb1d16acfe70c1ab78 (patch)
tree33d03a5db4eeb1597b5b67316c71980f6e1da169
parent0e4c4d7efc08d04c3c0ae960428b08ada37e4a91 (diff)
downloadsqlalchemy-26ed90ab22dde7bdafe933cb1d16acfe70c1ab78.tar.gz
- 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
-rw-r--r--doc/build/changelog/changelog_10.rst11
-rw-r--r--lib/sqlalchemy/orm/persistence.py2
-rw-r--r--test/orm/test_versioning.py37
3 files changed, 49 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index 974aa5f1a..950e2a5d9 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -19,6 +19,17 @@
: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
:versions: 1.1.0b1
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index 88c96e94c..77c513aef 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -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
diff --git a/test/orm/test_versioning.py b/test/orm/test_versioning.py
index 124053d47..07b090c60 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):