]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Major revisals to lambdas
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 12 Dec 2020 23:56:58 +0000 (18:56 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 16 Dec 2020 23:50:47 +0000 (18:50 -0500)
commit77c9534dcaf3723f7b2baf42442eda3e1d8c3332
treec8f46c2a936c08a8de1f156807a0a3f31dd9486c
parent09fac89debfbdcccbf2bcc433f7bec7921cf62be
Major revisals to lambdas

1. Improve coercions._deep_is_literal to check sequences
for clause elements, thus allowing a phrase like
lambda: col.in_([literal("x"), literal("y")]) to be handled

2. revise closure variable caching completely.   All variables
entering must be part of a closure cache key or rejected.
only objects that can be resolved to HasCacheKey or FunctionType
are accepted; all other types are rejected.  This adds a high
degree of strictness to lambdas and will make them a little more
awkward to use in some cases, however prevents several classes
of critical issues:

a. previously, a lambda that had an expression derived from
some kind of state, like "self.x", or "execution_context.session.foo"
would produce a closure cache key from "self" or "execution_context",
objects that can very well be per-execution and would therefore
cause a AnalyzedFunction objects to overflow. (memory won't leak
as it looks like an LRUCache is already used for these)

b. a lambda, such as one used within DeferredLamdaElement, that
produces different SQL expressions based on the arguments
(which is in fact what it's supposed to do), however it would
through the use of conditionals produce different bound parameter
combinations, leading to literal parameters not tracked properly.
These are now rejected as uncacheable whereas previously they would
again be part of the closure cache key, causing an overflow of
AnalyizedFunction objects.

3. Ensure non-mapped mixins are handled correctly by
with_loader_criteria().

4. Fixed bug in lambda SQL system where we are not supposed to allow a Python
function to be embedded in the lambda, since we can't predict a bound value
from it.   While there was an error condition added for this, it was not
tested and wasn't working; an informative error is now raised.

5. new docs for lambdas

6. consolidated changelog for all of these

Fixes: #5760
Fixes: #5765
Fixes: #5766
Fixes: #5768
Fixes: #5770
Change-Id: Iedaa636c3225fad496df23b612c516c8ab247ab7
19 files changed:
doc/build/changelog/unreleased_14/5760.rst [new file with mode: 0644]
doc/build/changelog/unreleased_14/5761.rst [deleted file]
doc/build/changelog/unreleased_14/5762.rst [deleted file]
doc/build/changelog/unreleased_14/5763.rst [deleted file]
doc/build/changelog/unreleased_14/5764.rst [deleted file]
doc/build/core/connections.rst
doc/build/errors.rst
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/sql/coercions.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/lambdas.py
test/aaa_profiling/test_orm.py
test/orm/test_lambdas.py
test/orm/test_relationship_criteria.py
test/orm/test_selectin_relations.py
test/profiles.txt
test/sql/test_compare.py
test/sql/test_lambdas.py