diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-03-23 17:48:07 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-03-23 17:48:07 +0000 |
| commit | 65c577583215d98423946d8d9bf377b63fc65e43 (patch) | |
| tree | 54708ebcd5a668999fe5ec4ae1d700a406217f66 /lib/sqlalchemy/sql | |
| parent | 8bf920d52ddd4ec5f62a00fb9db370a076aa375d (diff) | |
| parent | 242867ec87c4d739011ee3cea9a53f33d9f05f2b (diff) | |
| download | sqlalchemy-65c577583215d98423946d8d9bf377b63fc65e43.tar.gz | |
Merge "Adjust derivation rules for table vs. subquery against a join"
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 4300d8a29..4dec30a80 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -813,6 +813,7 @@ class ClauseAdapter(visitors.ReplacingExternalTraversal): exclude_fn=None, adapt_on_names=False, anonymize_labels=False, + adapt_from_selectables=None, ): self.__traverse_options__ = { "stop_on": [selectable], @@ -823,6 +824,7 @@ class ClauseAdapter(visitors.ReplacingExternalTraversal): self.exclude_fn = exclude_fn self.equivalents = util.column_dict(equivalents or {}) self.adapt_on_names = adapt_on_names + self.adapt_from_selectables = adapt_from_selectables def _corresponding_column( self, col, require_embedded, _seen=util.EMPTY_SET @@ -850,6 +852,13 @@ class ClauseAdapter(visitors.ReplacingExternalTraversal): if isinstance(col, FromClause) and not isinstance( col, functions.FunctionElement ): + if self.adapt_from_selectables: + for adp in self.adapt_from_selectables: + if adp.is_derived_from(col): + break + else: + return None + if self.selectable.is_derived_from(col): return self.selectable elif isinstance(col, Alias) and isinstance( @@ -875,6 +884,13 @@ class ClauseAdapter(visitors.ReplacingExternalTraversal): if "adapt_column" in col._annotations: col = col._annotations["adapt_column"] + if self.adapt_from_selectables and col not in self.equivalents: + for adp in self.adapt_from_selectables: + if adp.c.corresponding_column(col, False) is not None: + break + else: + return None + if self.include_fn and not self.include_fn(col): return None elif self.exclude_fn and self.exclude_fn(col): @@ -924,6 +940,7 @@ class ColumnAdapter(ClauseAdapter): adapt_on_names=False, allow_label_resolve=True, anonymize_labels=False, + adapt_from_selectables=None, ): ClauseAdapter.__init__( self, @@ -933,6 +950,7 @@ class ColumnAdapter(ClauseAdapter): exclude_fn=exclude_fn, adapt_on_names=adapt_on_names, anonymize_labels=anonymize_labels, + adapt_from_selectables=adapt_from_selectables, ) self.columns = util.WeakPopulateDict(self._locate_col) |
