diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-12-26 12:13:19 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-12-26 15:01:02 -0500 |
| commit | c1d2fbac4c399b47f4715f7ea2a1147374d2aa43 (patch) | |
| tree | acd54068d984771ee82a61c819e36a17c1aa85d1 /lib/sqlalchemy | |
| parent | 79e047806261e8d6690b0d8dacd641eba6d6e3ec (diff) | |
| download | sqlalchemy-c1d2fbac4c399b47f4715f7ea2a1147374d2aa43.tar.gz | |
include empty intermediary tables in optimized get
Fixed issue in joined-inheritance load of additional attributes
functionality in deep multi-level inheritance where an intermediary table
that contained no columns would not be included in the tables joined,
instead linking those tables to their primary key identifiers. While this
works fine, it nonetheless in 1.4 began producing the cartesian product
compiler warning. The logic has been changed so that these intermediary
tables are included regardless. While this does include additional tables
in the query that are not technically necessary, this only occurs for the
highly unusual case of deep 3+ level inheritance with intermediary tables
that have no non primary key columns, potential performance impact is
therefore expected to be negligible.
Fixes: #7507
Change-Id: Id2073773e97a0853b744b51feeb2bc4437032e51
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 60083bf4d..40a76181c 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -3022,23 +3022,28 @@ class Mapper( allconds = [] + start = False + + # as of #7507, from the lowest base table on upwards, + # we include all intermediary tables. + + for mapper in reversed(list(self.iterate_to_root())): + if mapper.local_table in tables: + start = True + elif not isinstance(mapper.local_table, expression.TableClause): + return None + if start and not mapper.single: + allconds.append(mapper.inherit_condition) + tables.add(mapper.local_table) + + # only the bottom table needs its criteria to be altered to fit + # the primary key ident - the rest of the tables upwards to the + # descendant-most class should all be present and joined to each + # other. try: - start = False - for mapper in reversed(list(self.iterate_to_root())): - if mapper.local_table in tables: - start = True - elif not isinstance( - mapper.local_table, expression.TableClause - ): - return None - if start and not mapper.single: - allconds.append( - visitors.cloned_traverse( - mapper.inherit_condition, - {}, - {"binary": visit_binary}, - ) - ) + allconds[0] = visitors.cloned_traverse( + allconds[0], {}, {"binary": visit_binary} + ) except _OptGetColumnsNotAvailable: return None |
