From 335cdea7c72c279f8cf9de278ac96f7dda2bca15 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 27 May 2022 16:07:01 -0400 Subject: remove "deannotate" from column_property expression Fixed issue where using a :func:`_orm.column_property` construct containing a subquery against an already-mapped column attribute would not correctly apply ORM-compilation behaviors to the subquery, including that the "IN" expression added for a single-table inherits expression would fail to be included. This fix involves a few tweaks in the ORM adaptation logic, including a missing "parententity" adaptation on the mapper side. The specific mechanics here have a lot of moving parts so we will continue to add tests to assert these cases. In particular a more complete test for issue #2316 is added that was relying upon the deannotate happening here. Fixes: #8064 Change-Id: Ia85dd12dcf6e7c002b30de4a27d7aa66cb3cd20e --- lib/sqlalchemy/orm/mapper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/orm/mapper.py') diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 2d3bceb92..2a227f9da 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1911,7 +1911,7 @@ class Mapper( self.columns.add(col, key) - for col in prop.columns + prop._orig_columns: + for col in prop.columns: for proxy_col in col.proxy_set: self._columntoproperty[proxy_col] = prop @@ -2260,9 +2260,9 @@ class Mapper( @HasMemoized.memoized_attribute def _single_table_criterion(self): if self.single and self.inherits and self.polymorphic_on is not None: - return self.polymorphic_on._annotate({"parentmapper": self}).in_( - [m.polymorphic_identity for m in self.self_and_descendants] - ) + return self.polymorphic_on._annotate( + {"parententity": self, "parentmapper": self} + ).in_([m.polymorphic_identity for m in self.self_and_descendants]) else: return None -- cgit v1.2.1