diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-06-30 09:22:00 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-06-30 09:23:02 -0400 |
commit | dee57477882f8876fd97071a790fe3d3ee2164c5 (patch) | |
tree | 7ad513edae9307cd4e3c8194ab7ee2899f30b9ac /test/dialect/postgresql/test_compiler.py | |
parent | 67edf8e376d4bf4baf5944b88dff1cb073e9ef72 (diff) | |
download | sqlalchemy-dee57477882f8876fd97071a790fe3d3ee2164c5.tar.gz |
apply quoting to "ON CONSTRAINT" symbol
Fixed issue in :meth:`_postgresql.Insert.on_conflict_do_nothing` and
:meth:`_postgresql.Insert.on_conflict_do_update` where the name of a unique
constraint passed as the ``constraint`` parameter would not be properly
quoted if it contained characters which required quoting.
Fixes: #6696
Change-Id: I4ffca9b8c72cef4ed39e2de96831ccc11a620422
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 2f91580a9..e48de9d21 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -28,6 +28,7 @@ from sqlalchemy import Text from sqlalchemy import text from sqlalchemy import tuple_ from sqlalchemy import types as sqltypes +from sqlalchemy import UniqueConstraint from sqlalchemy import update from sqlalchemy.dialects import postgresql from sqlalchemy.dialects.postgresql import aggregate_order_by @@ -2339,6 +2340,31 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL): "DO UPDATE SET myid = excluded.myid", ) + def test_do_nothing_quoted_string_constraint_target(self): + """test #6696""" + i = insert(self.table1, values=dict(name="foo")) + i = i.on_conflict_do_nothing(constraint="Some Constraint Name") + self.assert_compile( + i, + "INSERT INTO mytable (name) VALUES " + '(%(name)s) ON CONFLICT ON CONSTRAINT "Some Constraint Name" ' + "DO NOTHING", + ) + + def test_do_nothing_quoted_named_constraint_target(self): + """test #6696""" + i = insert(self.table1, values=dict(name="foo")) + unique_constr = UniqueConstraint( + self.table1.c.myid, name="Some Constraint Name" + ) + i = i.on_conflict_do_nothing(constraint=unique_constr) + self.assert_compile( + i, + "INSERT INTO mytable (name) VALUES " + '(%(name)s) ON CONFLICT ON CONSTRAINT "Some Constraint Name" ' + "DO NOTHING", + ) + def test_do_update_index_elements_where_target(self): i = insert(self.table1, values=dict(name="foo")) i = i.on_conflict_do_update( |