diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-11-11 11:13:27 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-11-11 11:36:06 -0500 |
| commit | 1f7969ae50d4be92f330d2cf6a2df9aba8b307bf (patch) | |
| tree | 4f69ab010b08db8cf6570849b25c4359cf463b97 /lib/sqlalchemy/sql | |
| parent | afb26d79d7b9256ee26b4d3b8550f7088f4b6249 (diff) | |
| download | sqlalchemy-1f7969ae50d4be92f330d2cf6a2df9aba8b307bf.tar.gz | |
Warn / raise for returning() / return_defaults() combinations
A warning is emmitted if a returning() method such as
:meth:`_sql.Insert.returning` is called multiple times, as this does not
yet support additive operation. Version 1.4 will support additive
operation for this. Additionally, any combination of the
:meth:`_sql.Insert.returning` and :meth:`_sql.Insert.return_defaults`
methods now raises an error as these methods are mutually exclusive;
previously the operation would fail silently.
Fixes: #5691
Change-Id: Id95e0f9da48bba0b59439cb26564f0daa684c8e3
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/dml.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index 5726cddc0..ddb85224a 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -207,6 +207,8 @@ class UpdateBase( _hints = util.immutabledict() named_with_column = False + _return_defaults = None + is_dml = True @classmethod @@ -343,11 +345,10 @@ class UpdateBase( for server_flag, updated_timestamp in connection.execute(stmt): print(server_flag, updated_timestamp) - The given collection of column expressions should be derived from - the table that is - the target of the INSERT, UPDATE, or DELETE. While - :class:`_schema.Column` - objects are typical, the elements can also be expressions:: + The given collection of column expressions should be derived from the + table that is the target of the INSERT, UPDATE, or DELETE. While + :class:`_schema.Column` objects are typical, the elements can also be + expressions:: stmt = table.insert().returning( (table.c.first_name + " " + table.c.last_name). @@ -383,6 +384,16 @@ class UpdateBase( """ + if self._return_defaults: + raise exc.InvalidRequestError( + "return_defaults() is already configured on this statement" + ) + if self._returning: + util.warn( + "The returning() method does not currently support multiple " + "additive calls. The existing RETURNING clause being " + "replaced by new columns." + ) self._returning = cols def _exported_columns_iterator(self): @@ -760,6 +771,10 @@ class ValuesBase(UpdateBase): :attr:`_engine.CursorResult.inserted_primary_key_rows` """ + if self._returning: + raise exc.InvalidRequestError( + "RETURNING is already configured on this statement" + ) self._return_defaults = cols or True |
