summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-12-20 10:26:09 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-12-20 10:26:35 -0500
commitae3c57f492c5ade1afd8b010f7d9f2db740eb595 (patch)
tree7c13aba96c4a09f4e7be6fe0d0f6114597308fe1 /test
parent2042493228a92fede38f39cd144d6ea74abbcb21 (diff)
downloadsqlalchemy-ae3c57f492c5ade1afd8b010f7d9f2db740eb595.tar.gz
- Fixed issue where a primary key column that has a Sequence on it,
yet the column is not the "auto increment" column, either because it has a foreign key constraint or ``autoincrement=False`` set, would attempt to fire the Sequence on INSERT for backends that don't support sequences, when presented with an INSERT missing the primary key value. This would take place on non-sequence backends like SQLite, MySQL. [ticket:2896]
Diffstat (limited to 'test')
-rw-r--r--test/sql/test_defaults.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py
index 79514eaf4..ae36e8b5a 100644
--- a/test/sql/test_defaults.py
+++ b/test/sql/test_defaults.py
@@ -603,6 +603,33 @@ class AutoIncrementTest(fixtures.TablesTest):
nonai.insert().execute(id=1, data='row 1')
+
+ def test_col_w_sequence_non_autoinc_no_firing(self):
+ metadata = self.metadata
+ # plain autoincrement/PK table in the actual schema
+ Table("x", metadata,
+ Column("set_id", Integer, primary_key=True)
+ )
+ metadata.create_all()
+
+ # for the INSERT use a table with a Sequence
+ # and autoincrement=False. Using a ForeignKey
+ # would have the same effect
+ dataset_no_autoinc = Table("x", MetaData(),
+ Column("set_id", Integer, Sequence("some_seq"),
+ primary_key=True, autoincrement=False)
+ )
+
+ testing.db.execute(
+ dataset_no_autoinc.insert()
+ )
+ eq_(
+ testing.db.scalar(dataset_no_autoinc.count()), 1
+ )
+
+
+
+
class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = 'default'
@@ -875,6 +902,7 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL):
assert not self._has_sequence('s1')
assert not self._has_sequence('s2')
+
cartitems = sometable = metadata = None
class TableBoundSequenceTest(fixtures.TestBase):
__requires__ = ('sequences',)