--- /dev/null
+.. change::
+ :tags: bug, ext
+ :tickets: 4185
+
+ 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.
# 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:
sp.children = 'c'
is_(SubParent.children.owning_class, Parent)
+ def test_resolved_to_correct_class_five(self):
+ Base = declarative_base()
+
+ class Mixin(object):
+ children = association_proxy('_children', 'value')
+
+ class Parent(Mixin, Base):
+ __tablename__ = 'parent'
+ id = Column(Integer, primary_key=True)
+ _children = relationship("Child")
+
+ class Child(Base):
+ __tablename__ = 'child'
+ parent_id = Column(
+ Integer, ForeignKey(Parent.id), primary_key=True)
+ value = Column(String)
+
+ # this triggers the owning routine, doesn't fail
+ Mixin.children
+
+ p1 = Parent()
+
+ c1 = Child(value='c1')
+ p1._children.append(c1)
+ is_(Parent.children.owning_class, Parent)
+ eq_(p1.children, ["c1"])
+
def test_never_assign_nonetype(self):
foo = association_proxy('x', 'y')
foo._calc_owner(None, None)