diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-17 20:08:10 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-17 23:14:24 -0500 |
| commit | c8d7141c79829f36e123bf3e4be1721dd34aaeb4 (patch) | |
| tree | a3e985be4eb5a73f52f18e1c254831da516ca38b /lib/sqlalchemy | |
| parent | 0717ce9d1dc28b67b4568351f4e98e59a831b1f1 (diff) | |
| download | sqlalchemy-c8d7141c79829f36e123bf3e4be1721dd34aaeb4.tar.gz | |
Adapt single inh criteria more specifically
Fixed issue where when using single-table inheritance in conjunction with a
joined inheritance hierarchy that uses "with polymorphic" loading, the
"single table criteria" for that single-table entity could get confused for
that of other entities from the same hierarchy used in the same query.The
adaption of the "single table criteria" is made more specific to the target
entity to avoid it accidentally getting adapted to other tables in the
query.
Change-Id: Ia9f915a4b01e8bb9cee365c4c70e00c626f103c4
Fixes: #4454
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 56ad965de..a394ec06e 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -2103,7 +2103,7 @@ class Mapper(InspectionAttr): @_memoized_configured_property def _single_table_criterion(self): if self.single and self.inherits and self.polymorphic_on is not None: - return self.polymorphic_on.in_( + return self.polymorphic_on._annotate({"parentmapper": self}).in_( m.polymorphic_identity for m in self.self_and_descendants ) else: diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 7ddcf10b0..2bd79a2cd 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -364,7 +364,6 @@ class Query(object): or "_orm_adapt" in elem._annotations or "parententity" in elem._annotations ): - e = adapter(elem) if e is not None: return e @@ -3933,6 +3932,7 @@ class Query(object): if single_crit is not None: if adapter: single_crit = adapter.traverse(single_crit) + single_crit = self._adapt_clause(single_crit, False, False) context.whereclause = sql.and_( sql.True_._ifnone(context.whereclause), single_crit |
