summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/selectable.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-11-16 00:01:33 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-11-16 00:01:33 +0000
commit073553be44a8be2ebff2e5893a4f1797b1e57681 (patch)
tree36f2deee7771b693847687a3b7f1ce083f9db107 /lib/sqlalchemy/sql/selectable.py
parente723db6c46aa5a24681bef349b97c287dc74de8f (diff)
parent93dc7ea1502c37793011b094447641361aff5aba (diff)
downloadsqlalchemy-073553be44a8be2ebff2e5893a4f1797b1e57681.tar.gz
Merge "don't invoke fromclause.c when creating an annotated" into main
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r--lib/sqlalchemy/sql/selectable.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index 23260a985..08d01c883 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -6753,8 +6753,28 @@ TextAsFrom = TextualSelect
class AnnotatedFromClause(Annotated):
- def __init__(self, element, values):
- # force FromClause to generate their internal
- # collections into __dict__
- element.c
- Annotated.__init__(self, element, values)
+ def _copy_internals(self, **kw):
+ super()._copy_internals(**kw)
+ if kw.get("ind_cols_on_fromclause", False):
+ ee = self._Annotated__element # type: ignore
+
+ self.c = ee.__class__.c.fget(self) # type: ignore
+
+ @util.ro_memoized_property
+ def c(self) -> ReadOnlyColumnCollection[str, KeyedColumnElement[Any]]:
+ """proxy the .c collection of the underlying FromClause.
+
+ Originally implemented in 2008 as a simple load of the .c collection
+ when the annotated construct was created (see d3621ae961a), in modern
+ SQLAlchemy versions this can be expensive for statements constructed
+ with ORM aliases. So for #8796 SQLAlchemy 2.0 we instead proxy
+ it, which works just as well.
+
+ Two different use cases seem to require the collection either copied
+ from the underlying one, or unique to this AnnotatedFromClause.
+
+ See test_selectable->test_annotated_corresponding_column
+
+ """
+ ee = self._Annotated__element # type: ignore
+ return ee.c # type: ignore