]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
introduce generalized decorator to prevent invalid method calls
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 16 Jan 2021 17:39:51 +0000 (12:39 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 16 Jan 2021 23:44:21 +0000 (18:44 -0500)
commit8860117c9655a4bdeafebab1c6ef12c6a6198e66
tree7fc8743f78b6d4f1ae183265abec76e11560232c
parent6137d223be8e596fb2d7c78623ab22162db8ea6e
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
lib/sqlalchemy/dialects/mysql/dml.py
lib/sqlalchemy/dialects/postgresql/dml.py
lib/sqlalchemy/dialects/sqlite/dml.py
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/sql/dml.py
test/dialect/mysql/test_compiler.py
test/dialect/postgresql/test_compiler.py
test/dialect/test_sqlite.py
test/sql/test_update.py