From 66a246bd31730d53fb6b0e606d67ea4247f5e56c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 20 Feb 2018 12:15:57 -0500 Subject: Default to using current mapped class as owner if none found Repaired regression caused in 1.2.3 and 1.1.16 regarding association proxy objects, revising the approach to :ticket:`4185` when calculating the "owning class" of an association proxy to default to choosing the current class if the proxy object is not directly associated with a mapped class, such as a mixin. Change-Id: I87d0ac09f695dc285bd4bbe0a547f1d5ce23e068 Fixes: #4185 --- lib/sqlalchemy/ext/associationproxy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/ext') diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 72200c5e2..1ebc7b420 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -271,7 +271,12 @@ class AssociationProxy(interfaces.InspectionAttrInfo): # note we can get our real .key here too owner = insp.mapper.class_manager._locate_owning_manager(self) - self.owning_class = owner.class_ + if owner is not None: + self.owning_class = owner.class_ + else: + # the proxy is attached to a class that is not mapped + # (like a mixin), we are mapped, so, it's us. + self.owning_class = target_cls def __get__(self, obj, class_): if self.owning_class is None: -- cgit v1.2.1