diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-10-18 15:43:27 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-10-18 15:55:12 -0400 |
commit | 6da8c6d0299b055414d3350f4c2d73f9e911d7ae (patch) | |
tree | e22f04666ccdde2013cd4ea8c985e6704ca3c75b /lib/sqlalchemy/sql | |
parent | 68479d40726425c3b3a17f12658927db8ad9fe84 (diff) | |
download | sqlalchemy-6da8c6d0299b055414d3350f4c2d73f9e911d7ae.tar.gz |
use coercions for label element, ensure propagate_attrs
Fixed bug where the ORM "plugin", necessary for features such as
:func:`_orm.with_loader_criteria` to work correctly, would not be applied
to a :func:`_sql.select` which queried from an ORM column expression if it
made use of the :meth:`_sql.ColumnElement.label` modifier.
Fixes: #7205
Change-Id: I72b84442e14df8b5ece33916f3c51ca3f358864b
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index e49665019..3699f872b 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -4521,19 +4521,31 @@ class Label(roles.LabeledColumnExprRole, ColumnElement): """ - if isinstance(element, Label): - self._resolve_label = element._label - + orig_element = element + element = coercions.expect( + roles.ExpressionElementRole, + element, + apply_propagate_attrs=self, + ) while isinstance(element, Label): + # TODO: this is only covered in test_text.py, but nothing + # fails if it's removed. determine rationale element = element.element if name: self.name = name + + # TODO: nothing fails if this is removed. this is related + # to the order_by() string feature tested in test_text.py. self._resolve_label = self.name else: self.name = _anonymous_label.safe_construct( id(self), getattr(element, "name", "anon") ) + if isinstance(orig_element, Label): + # TODO: no coverage for this block, again would be in + # test_text.py where the resolve_label concept is important + self._resolve_label = orig_element._label self.key = self._tq_label = self._tq_key_label = self.name self._element = element |