summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-28 09:56:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-28 13:39:59 -0400
commit41ac0c7187daed54b0ba44b2287b6679d95d2caa (patch)
treed0a262379c26aadf0dc2a333b4d863e127ae6928 /lib/sqlalchemy
parent2af1b107fce34b15898e6f534097ad34cfd7d503 (diff)
downloadsqlalchemy-41ac0c7187daed54b0ba44b2287b6679d95d2caa.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/attributes.py1
-rw-r--r--lib/sqlalchemy/orm/context.py3
2 files changed, 3 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 0c7bc4cf0..b8974196c 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -227,6 +227,7 @@ class QueryableAttribute(
else:
annotations = {
"proxy_key": self.key,
+ "proxy_owner": self.class_,
"entity_namespace": self._entity_namespace,
}
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