diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-10-03 17:36:27 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-10-07 23:06:06 -0400 |
| commit | 65aee6cce57fd1cca3a95814feff3ed99a5a51ee (patch) | |
| tree | 0352d74938902a9242dfb97ca5215d9191a2ad16 /lib/sqlalchemy/sql/selectable.py | |
| parent | ebd9788c986c56b8b845fa83609a6eb2c0cef083 (diff) | |
| download | sqlalchemy-65aee6cce57fd1cca3a95814feff3ed99a5a51ee.tar.gz | |
Add result map targeting for custom compiled, text objects
In order for text(), custom compiled objects, etc. to be usable
by Query(), they are all targeted by object key in the result map.
As we no longer want Query to implicitly label these, as well as that
text() has no label feature, support adding entries to the result
map that have no name, key, or type, only the object itself, and
then ensure that the compiler sets up for positional targeting
when this condition is detected.
Allows for more flexible ORM query usage with custom expressions
and text() while having less special logic in query itself.
Fixes: #4887
Change-Id: Ie073da127d292d43cb132a2b31bc90af88bfe2fd
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index ddbcdf91d..6282cf2ee 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -4191,8 +4191,9 @@ class Select( def name_for_col(c): if c._label is None or not c._render_label_in_columns_clause: - return (None, c) + return (None, c, False) + repeated = False name = c._label if name in names: @@ -4218,19 +4219,22 @@ class Select( # subsequent occurrences of the column so that the # original stays non-ambiguous name = c._dedupe_label_anon_label + repeated = True else: names[name] = c elif anon_for_dupe_key: # same column under the same name. apply the "dedupe" # label so that the original stays non-ambiguous name = c._dedupe_label_anon_label + repeated = True else: names[name] = c - return name, c + return name, c, repeated return [name_for_col(c) for c in cols] else: - return [(None, c) for c in cols] + # repeated name logic only for use labels at the moment + return [(None, c, False) for c in cols] @_memoized_property def _columns_plus_names(self): @@ -4245,7 +4249,7 @@ class Select( keys_seen = set() prox = [] - for name, c in self._generate_columns_plus_names(False): + for name, c, repeated in self._generate_columns_plus_names(False): if not hasattr(c, "_make_proxy"): continue if name is None: |
