From 0e46359cb00b453448e37ec16fce744f73c98581 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 12 Jul 2021 18:19:08 -0400 Subject: 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 --- test/dialect/postgresql/test_compiler.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/dialect/postgresql/test_compiler.py') 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")) -- cgit v1.2.1