From 41ac0c7187daed54b0ba44b2287b6679d95d2caa Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 28 Apr 2021 09:56:15 -0400 Subject: add optional proxy_class to track w/ proxy_key Fixed regression in ORM where using hybrid property to indicate an expression from a different entity would confuse the column-labeling logic in the ORM and attempt to derive the name of the hybrid from that other class, leading to an attribute error. The owning class of the hybrid attribute is now tracked along with the name. Fixes: #6386 Change-Id: Ica9497ea34fef799d6265de44104c1f3f3b30232 --- lib/sqlalchemy/orm/context.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/orm/context.py') diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index 6cdad9f41..042acc9c5 100644 --- a/lib/sqlalchemy/orm/context.py +++ b/lib/sqlalchemy/orm/context.py @@ -2691,8 +2691,9 @@ class _ORMColumnEntity(_ColumnEntity): # within internal loaders. orm_key = annotations.get("proxy_key", None) + proxy_owner = annotations.get("proxy_owner", _entity.entity) if orm_key: - self.expr = getattr(_entity.entity, orm_key) + self.expr = getattr(proxy_owner, orm_key) self.translate_raw_column = False else: # if orm_key is not present, that means this is an ad-hoc -- cgit v1.2.1