diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-13 11:49:43 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-15 13:46:02 -0500 |
| commit | 93dc7ea1502c37793011b094447641361aff5aba (patch) | |
| tree | 2a443b0b902777771e6b18a499e6527de31ee729 /lib/sqlalchemy/orm | |
| parent | 5fc22d0e645cd560db43fb7fd5072ecbab06128b (diff) | |
| download | sqlalchemy-93dc7ea1502c37793011b094447641361aff5aba.tar.gz | |
don't invoke fromclause.c when creating an annotated
The ``aliased()`` constructor calls upon ``__clause_element__()``,
which internally annotates a ``FromClause``, like a subquery.
This became expensive as ``AnnotatedFromClause`` has for
many years called upon ``element.c`` so that the full ``.c``
collection is transferred to the Annotated.
Taking this out proved to be challenging. A straight remove
seemed to not break any tests except for the one that
tested the exact condition. Nevertheless this seemed
"spooky" so I instead moved the get of ``.c`` to be in a
memoized proxy method. However, that then exposed
a recursion issue related to loader_criteria; so the
source of that behavior, which was an accidental behavioral
artifact, is now made into an explcicit option that
loader_criteria uses directly.
The accidental behavioral artifact in question is still
kind of strange since I was not able to fully trace out
how it works, but the end result is that fixing the
artifact to be "correct" causes loader_criteria, within
the particular test for #7491, creates a select/
subquery structure with a cycle in it, so compilation fails
with recursion overflow.
The "solution" is to cause the artifact to occur in this
case, which is that the ``AnnotatedFromClause`` will have a
different ``.c`` collection than its element, which is a
subquery. It's not totally clear how a cycle is generated
when this is not done.
This is commit one of two, which goes through
some hoops to make essentially a one-line change.
The next commit will rework ColumnCollection to optimize
the corresponding_column() method significantly.
Fixes: #8796
Change-Id: Id58ae6554db62139462c11a8be7313a3677456ad
Diffstat (limited to 'lib/sqlalchemy/orm')
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 6cd98f5ea..50eba5d4c 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -1317,7 +1317,10 @@ class LoaderCriteriaOption(CriteriaOption): crit = self.where_criteria # type: ignore assert isinstance(crit, ColumnElement) return sql_util._deep_annotate( - crit, {"for_loader_criteria": self}, detect_subquery_cols=True + crit, + {"for_loader_criteria": self}, + detect_subquery_cols=True, + ind_cols_on_fromclause=True, ) def process_compile_state_replaced_entities( @@ -1416,6 +1419,8 @@ class Bundle( _propagate_attrs: _PropagateAttrsType = util.immutabledict() + proxy_set = util.EMPTY_SET # type: ignore + exprs: List[_ColumnsClauseElement] def __init__( |
