summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-07-12 18:19:08 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-07-13 10:15:07 -0400
commit0e46359cb00b453448e37ec16fce744f73c98581 (patch)
tree1be1d75ff64887dc134a9b424c154339b95ba862 /test/dialect/postgresql/test_compiler.py
parentca52e87268fec966f6005b1e4aa30206ae895e9e (diff)
downloadsqlalchemy-0e46359cb00b453448e37ec16fce744f73c98581.tar.gz
Extract format_constraint truncation rules to ON CONFLICT
Fixed issue where a too-long constraint name rendered as part of the "ON CONFLICT ON CONSTRAINT" element of the :class:`_postgresql.Insert` construct due to naming convention generation would not correctly truncate the name in the same way that it normally renders within a CREATE TABLE statement, thus producing a non-matching and too-long constraint name. Fixes: #6755 Change-Id: Ib27014a5ecbc9cd5861a396f8bb49fbc60bf49fe
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index e48de9d21..73b3051f9 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -2351,6 +2351,32 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL):
"DO NOTHING",
)
+ def test_do_nothing_super_long_name_constraint_target(self):
+ """test #6755"""
+
+ m = MetaData(
+ naming_convention={"uq": "%(table_name)s_%(column_0_N_name)s_key"}
+ )
+
+ uq = UniqueConstraint("some_column_name_thats_really_really_long_too")
+ Table(
+ "some_table_name_thats_really_really",
+ m,
+ Column("some_column_name_thats_really_really_long_too", Integer),
+ uq,
+ )
+
+ i = insert(self.table1, values=dict(name="foo"))
+
+ i = i.on_conflict_do_nothing(constraint=uq)
+ self.assert_compile(
+ i,
+ "INSERT INTO mytable (name) VALUES (%(name)s) ON CONFLICT "
+ "ON CONSTRAINT "
+ "some_table_name_thats_really_really_some_column_name_th_f7ab "
+ "DO NOTHING",
+ )
+
def test_do_nothing_quoted_named_constraint_target(self):
"""test #6696"""
i = insert(self.table1, values=dict(name="foo"))