diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-07-09 21:29:40 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-07-09 21:29:40 +0000 |
| commit | ca52e87268fec966f6005b1e4aa30206ae895e9e (patch) | |
| tree | 179bd2b61fbb50c114e0617e06913b8c5917357b /lib/sqlalchemy | |
| parent | a457e555e0b1cc8aca79270f2330b5fdef78eafb (diff) | |
| parent | 4e1b2ee4cb345f499bdfbff6c393efbebd8e1e72 (diff) | |
| download | sqlalchemy-ca52e87268fec966f6005b1e4aa30206ae895e9e.tar.gz | |
Merge "Add additional support to honor _proxy_key in Core selects"
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/context.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 15 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 15 |
3 files changed, 25 insertions, 7 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index 26e35b66e..0af3fd6af 100644 --- a/lib/sqlalchemy/orm/context.py +++ b/lib/sqlalchemy/orm/context.py @@ -2890,7 +2890,7 @@ class _ORMColumnEntity(_ColumnEntity): ezero._adapter if ezero.is_aliased_class else None, ) - if column._annotations: + if column._annotations and not column._expression_label: # annotated columns perform more slowly in compiler and # result due to the __eq__() method, so use deannotated column = column._deannotate() diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 73311f110..173314abe 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -887,6 +887,21 @@ class ColumnElement( else: return getattr(self, "name", "_no_label") + @util.memoized_property + def _expression_label(self): + """a suggested label to use in the case that the column has no name, + which should be used if possible as the explicit 'AS <label>' + where this expression would normally have an anon label. + + """ + + if getattr(self, "name", None) is not None: + return None + elif self._annotations and "proxy_key" in self._annotations: + return self._annotations["proxy_key"] + else: + return None + def _make_proxy( self, selectable, name=None, key=None, name_is_truncatable=False, **kw ): diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 0092fe094..235c74ea7 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -5815,14 +5815,17 @@ class Select( repeated = c._anon_name_label in names names[c._anon_name_label] = c return (None, c, repeated) + else: + name = effective_name = c._label elif getattr(c, "name", None) is None: # this is a scalar_select(). need to improve this case - repeated = c._anon_name_label in names - names[c._anon_name_label] = c - return (None, c, repeated) - - if use_tablename_labels: - name = effective_name = c._label + expr_label = c._expression_label + if expr_label is None: + repeated = c._anon_name_label in names + names[c._anon_name_label] = c + return (None, c, repeated) + else: + name = effective_name = expr_label else: name = None effective_name = c.name |
