summaryrefslogtreecommitdiff
path: root/test/orm
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-05-22 14:47:26 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-05-22 14:47:26 -0400
commit0a67c1305266ba9c4558e371fa9b193788c65bea (patch)
treed99b23444c8331a4e495fa2d56946f61c95c4ed3 /test/orm
parentda1bc9878b71f6f7b87e2fa7895e1631ae581609 (diff)
downloadsqlalchemy-0a67c1305266ba9c4558e371fa9b193788c65bea.tar.gz
Detect no params w/ manual version_id counter and set to itself
Fixed bug where programmatic version_id counter in conjunction with joined table inheritance would fail if the version_id counter were not actually incremented and no other values on the base table were modified, as the UPDATE would have an empty SET clause. Since programmatic version_id where version counter is not incremented is a documented use case, this specific condition is now detected and the UPDATE now sets the version_id value to itself, so that concurrency checks still take place. Change-Id: I80e385bffeed4851cc20131cbe983c173a46f655 Fixes: #3996
Diffstat (limited to 'test/orm')
-rw-r--r--test/orm/test_versioning.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/orm/test_versioning.py b/test/orm/test_versioning.py
index 40b373097..4c339d3bb 100644
--- a/test/orm/test_versioning.py
+++ b/test/orm/test_versioning.py
@@ -1284,3 +1284,65 @@ class ManualVersionTest(fixtures.MappedTest):
sess.commit()
eq_(a1.vid, 2)
+
+
+class ManualInheritanceVersionTest(fixtures.MappedTest):
+ run_define_tables = 'each'
+ __backend__ = True
+
+ @classmethod
+ def define_tables(cls, metadata):
+ Table(
+ "a", metadata,
+ Column(
+ 'id', Integer, primary_key=True,
+ test_needs_autoincrement=True),
+ Column('data', String(30)),
+ Column('vid', Integer, nullable=False)
+ )
+
+ Table(
+ "b", metadata,
+ Column(
+ 'id', Integer, ForeignKey('a.id'), primary_key=True),
+ Column('b_data', String(30)),
+ )
+
+ @classmethod
+ def setup_classes(cls):
+ class A(cls.Basic):
+ pass
+
+ class B(A):
+ pass
+
+ @classmethod
+ def setup_mappers(cls):
+ mapper(
+ cls.classes.A, cls.tables.a, version_id_col=cls.tables.a.c.vid,
+ version_id_generator=False)
+
+ mapper(
+ cls.classes.B, cls.tables.b, inherits=cls.classes.A)
+
+ def test_no_increment(self):
+ sess = Session()
+ b1 = self.classes.B()
+
+ b1.vid = 1
+ b1.data = 'd1'
+ sess.add(b1)
+ sess.commit()
+
+ # change col on subtable only without
+ # incrementing version id
+ b1.b_data = 'bd2'
+ sess.commit()
+
+ eq_(b1.vid, 1)
+
+ b1.b_data = 'd3'
+ b1.vid = 2
+ sess.commit()
+
+ eq_(b1.vid, 2)