diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-27 16:07:01 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-29 16:10:54 -0400 |
commit | 335cdea7c72c279f8cf9de278ac96f7dda2bca15 (patch) | |
tree | c43698d8dee5c0c4b70de2516acfe52476f00187 /lib/sqlalchemy/orm | |
parent | 21ae13765d7410228672a282fef29fc0e2b3b098 (diff) | |
download | sqlalchemy-335cdea7c72c279f8cf9de278ac96f7dda2bca15.tar.gz |
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
Diffstat (limited to 'lib/sqlalchemy/orm')
-rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/properties.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/util.py | 2 |
3 files changed, 6 insertions, 15 deletions
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 diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 7655f3ae2..d77d6e63c 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -38,7 +38,6 @@ from .interfaces import MapperProperty from .interfaces import PropComparator from .interfaces import StrategizedProperty from .relationships import Relationship -from .util import _orm_full_deannotate from .. import exc as sa_exc from .. import ForeignKey from .. import log @@ -103,7 +102,6 @@ class ColumnProperty( _links_to_entity = False columns: List[NamedColumn[Any]] - _orig_columns: List[NamedColumn[Any]] _is_polymorphic_discriminator: bool @@ -112,7 +110,6 @@ class ColumnProperty( comparator_factory: Type[PropComparator[_T]] __slots__ = ( - "_orig_columns", "columns", "group", "deferred", @@ -148,14 +145,8 @@ class ColumnProperty( attribute_options=attribute_options ) columns = (column,) + additional_columns - self._orig_columns = [ - coercions.expect(roles.LabeledColumnExprRole, c) for c in columns - ] self.columns = [ - _orm_full_deannotate( - coercions.expect(roles.LabeledColumnExprRole, c) - ) - for c in columns + coercions.expect(roles.LabeledColumnExprRole, c) for c in columns ] self.group = group self.deferred = deferred diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 520c95672..c8c802d9f 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -475,7 +475,7 @@ class ORMAdapter(sql_util.ColumnAdapter): def _include_fn(self, elem): entity = elem._annotations.get("parentmapper", None) - return not entity or entity.isa(self.mapper) + return not entity or entity.common_parent(self.mapper) class AliasedClass( |