diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-16 12:39:51 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-16 18:44:21 -0500 |
| commit | 8860117c9655a4bdeafebab1c6ef12c6a6198e66 (patch) | |
| tree | 7fc8743f78b6d4f1ae183265abec76e11560232c /lib/sqlalchemy/dialects/mysql/dml.py | |
| parent | 6137d223be8e596fb2d7c78623ab22162db8ea6e (diff) | |
| download | sqlalchemy-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 'lib/sqlalchemy/dialects/mysql/dml.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/dml.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/dml.py b/lib/sqlalchemy/dialects/mysql/dml.py index 9f8177c59..6c50dcca9 100644 --- a/lib/sqlalchemy/dialects/mysql/dml.py +++ b/lib/sqlalchemy/dialects/mysql/dml.py @@ -1,5 +1,6 @@ from ... import exc from ... import util +from ...sql.base import _exclusive_against from ...sql.base import _generative from ...sql.dml import Insert as StandardInsert from ...sql.elements import ClauseElement @@ -49,6 +50,13 @@ class Insert(StandardInsert): return alias(self.table, name="inserted") @_generative + @_exclusive_against( + "_post_values_clause", + msgs={ + "_post_values_clause": "This Insert construct already " + "has an ON DUPLICATE KEY clause present" + }, + ) def on_duplicate_key_update(self, *args, **kw): r""" Specifies the ON DUPLICATE KEY UPDATE clause. |
