From c315c7401a2aa00a8a0fa0f7d4189a9976fd7962 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 3 Apr 2022 11:28:57 -0400 Subject: TableValuedAlias generation fixes Fixed bug in newly implemented :paramref:`.FunctionElement.table_valued.joins_implicitly` feature where the parameter would not automatically propagate from the original :class:`.TableValuedAlias` object to the secondary object produced when calling upon :meth:`.TableValuedAlias.render_derived` or :meth:`.TableValuedAlias.alias`. Additionally repaired these issues in :class:`.TableValuedAlias`: * repaired a potential memory issue which could occur when repeatedly calling :meth:`.TableValuedAlias.render_derived` against successive copies of the same object (for .alias(), we currently have to still continue chaining from the previous element. not sure if this can be improved but this is standard behavior for .alias() elsewhere) * repaired issue where the individual element types would be lost when calling upon :meth:`.TableValuedAlias.render_derived` or :meth:`.TableValuedAlias.alias`. Fixes: #7890 Change-Id: Ie5120c7ff1e5c1bba5aaf77c782a51c637860208 --- lib/sqlalchemy/sql/selectable.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 24edc1cae..4f6e3795e 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1534,10 +1534,17 @@ class TableValuedAlias(Alias): """ - tva = TableValuedAlias._construct(self, name=name) + tva = TableValuedAlias._construct( + self, + name=name, + table_value_type=self._tableval_type, + joins_implicitly=self.joins_implicitly, + ) + if self._render_derived: tva._render_derived = True tva._render_derived_w_types = self._render_derived_w_types + return tva def lateral(self, name=None): @@ -1598,7 +1605,15 @@ class TableValuedAlias(Alias): # python id() of the original which can cause name conflicts if # a new anon-name grabs the same identifier as the local anon-name # (just saw it happen on CI) - new_alias = TableValuedAlias._construct(self, name=name) + + # construct against original to prevent memory growth + # for repeated generations + new_alias = TableValuedAlias._construct( + self.element, + name=name, + table_value_type=self._tableval_type, + joins_implicitly=self.joins_implicitly, + ) new_alias._render_derived = True new_alias._render_derived_w_types = with_types return new_alias -- cgit v1.2.1