diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-26 10:37:21 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-26 13:01:05 -0400 |
commit | 56f9c7743e9083add69a10501a503f4e25bb59d7 (patch) | |
tree | 43debd5fd0b2d90df87975d7c85d36a5e20da328 /lib/sqlalchemy/sql/elements.py | |
parent | 784d32edff03cd960d0c47768f7ef0d0a438463e (diff) | |
download | sqlalchemy-56f9c7743e9083add69a10501a503f4e25bb59d7.tar.gz |
Adapt loader_criteria params for current query
Fixed critical issue in the new :meth:`_orm.PropComparator.and_` feature
where loader strategies that emit secondary SELECT statements such as
:func:`_orm.selectinload` and :func:`_orm.lazyload` would fail to
accommodate for bound parameters in the user-defined criteria in terms of
the current statement being executed, as opposed to the cached statement,
causing stale bound values to be used.
This also adds a warning for the case where an object that uses
:func:`_orm.lazyload` in conjunction with :meth:`_orm.PropComparator.and_`
is attempted to be serialized; the loader criteria cannot reliably
be serialized and deserialized and eager loading should be used for this
case.
Fixes: #6139
Change-Id: I5a638bbecb7b583db2d3c0b76469f5a25c13dd3b
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 74e8dceff..b64427d51 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -235,7 +235,7 @@ class ClauseElement( self._propagate_attrs = util.immutabledict(values) return self - def _clone(self): + def _clone(self, **kw): """Create a shallow copy of this ClauseElement. This method may be used by a generative API. Its also used as @@ -360,7 +360,9 @@ class ClauseElement( if unique: bind._convert_to_unique() - return cloned_traverse(self, {}, {"bindparam": visit_bindparam}) + return cloned_traverse( + self, {"maintain_key": True}, {"bindparam": visit_bindparam} + ) def compare(self, other, **kw): r"""Compare this :class:`_expression.ClauseElement` to @@ -1432,8 +1434,8 @@ class BindParameter(roles.InElementRole, ColumnElement): c.type = type_ return c - def _clone(self, maintain_key=False): - c = ClauseElement._clone(self) + def _clone(self, maintain_key=False, **kw): + c = ClauseElement._clone(self, **kw) if not maintain_key and self.unique: c.key = _anonymous_label.safe_construct( id(c), c._orig_key or "param" |