summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-01-16 12:39:51 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-16 18:44:21 -0500
commit8860117c9655a4bdeafebab1c6ef12c6a6198e66 (patch)
tree7fc8743f78b6d4f1ae183265abec76e11560232c /test/dialect/postgresql/test_compiler.py
parent6137d223be8e596fb2d7c78623ab22162db8ea6e (diff)
downloadsqlalchemy-8860117c9655a4bdeafebab1c6ef12c6a6198e66.tar.gz
introduce generalized decorator to prevent invalid method calls
This introduces the ``_exclusive_against()`` utility decorator that can be used to prevent repeated invocations of methods that typically should only be called once. An informative error message is now raised for a selected set of DML methods (currently all part of :class:`_dml.Insert` constructs) if they are called a second time, which would implicitly cancel out the previous setting. The methods altered include: :class:`_sqlite.Insert.on_conflict_do_update`, :class:`_sqlite.Insert.on_conflict_do_nothing` (SQLite), :class:`_postgresql.Insert.on_conflict_do_update`, :class:`_postgresql.Insert.on_conflict_do_nothing` (PostgreSQL), :class:`_mysql.Insert.on_duplicate_key_update` (MySQL) Fixes: #5169 Change-Id: I9278fa87cd3470dcf296ff96bb0fb17a3236d49d
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index b3a0b9bbd..eb39091ae 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -1842,6 +1842,27 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL):
"goofy_index", table1.c.name, postgresql_where=table1.c.name > "m"
)
+ def test_on_conflict_do_no_call_twice(self):
+ users = self.table1
+
+ for stmt in (
+ insert(users).on_conflict_do_nothing(),
+ insert(users).on_conflict_do_update(
+ index_elements=[users.c.myid], set_=dict(name="foo")
+ ),
+ ):
+ for meth in (
+ stmt.on_conflict_do_nothing,
+ stmt.on_conflict_do_update,
+ ):
+
+ with testing.expect_raises_message(
+ exc.InvalidRequestError,
+ "This Insert construct already has an "
+ "ON CONFLICT clause established",
+ ):
+ meth()
+
def test_do_nothing_no_target(self):
i = insert(