diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-07-21 11:18:01 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-07-21 13:57:22 -0400 |
commit | a34a4af8a80f4edd12b022753b69065025818e20 (patch) | |
tree | 379a4060304439f46a6515b9b8c6cd74553c477e /lib/sqlalchemy/sql/dml.py | |
parent | e7119aea7870f0322e78d3a2cb28337b1640f0c2 (diff) | |
download | sqlalchemy-a34a4af8a80f4edd12b022753b69065025818e20.tar.gz |
implement cache key for return_defaults token
Fixed critical caching issue where the ORM's persistence feature using
INSERT..RETURNING would cache an incorrect query when mixing the "bulk
save" and standard "flush" forms of INSERT.
Fixes: #6793
Change-Id: Ifeb61c1226d3fa6d5e1c2e29b6f5ff77a27d6a2d
Diffstat (limited to 'lib/sqlalchemy/sql/dml.py')
-rw-r--r-- | lib/sqlalchemy/sql/dml.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index 048475040..158cb40f2 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -214,7 +214,8 @@ class UpdateBase( _hints = util.immutabledict() named_with_column = False - _return_defaults = None + _return_defaults = False + _return_defaults_columns = None _returning = () is_dml = True @@ -794,7 +795,8 @@ class ValuesBase(UpdateBase): :attr:`_engine.CursorResult.inserted_primary_key_rows` """ - self._return_defaults = cols or True + self._return_defaults = True + self._return_defaults_columns = cols class Insert(ValuesBase): @@ -825,6 +827,11 @@ class Insert(ValuesBase): ("_post_values_clause", InternalTraversal.dp_clauseelement), ("_returning", InternalTraversal.dp_clauseelement_list), ("_hints", InternalTraversal.dp_table_hint_list), + ("_return_defaults", InternalTraversal.dp_boolean), + ( + "_return_defaults_columns", + InternalTraversal.dp_clauseelement_list, + ), ] + HasPrefixes._has_prefixes_traverse_internals + DialectKWArgs._dialect_kwargs_traverse_internals @@ -929,7 +936,10 @@ class Insert(ValuesBase): if dialect_kw: self._validate_dialect_kwargs_deprecated(dialect_kw) - self._return_defaults = return_defaults + if return_defaults: + self._return_defaults = True + if not isinstance(return_defaults, bool): + self._return_defaults_columns = return_defaults @_generative def inline(self): @@ -1116,6 +1126,11 @@ class Update(DMLWhereBase, ValuesBase): ("_values", InternalTraversal.dp_dml_values), ("_returning", InternalTraversal.dp_clauseelement_list), ("_hints", InternalTraversal.dp_table_hint_list), + ("_return_defaults", InternalTraversal.dp_boolean), + ( + "_return_defaults_columns", + InternalTraversal.dp_clauseelement_list, + ), ] + HasPrefixes._has_prefixes_traverse_internals + DialectKWArgs._dialect_kwargs_traverse_internals |