try to add a real "replace collection" to association proxy

Issue #2642 new
Mike Bayer repo owner created an issue

the "clear" here is clumsy and originally thought was the ultimate cause of the original issue in #2637 it's not. Might be nicer if we had a bulk replace built in for those collections, would emit fewer events.

    def __set__(self, obj, values):
        if self.owning_class is None:
            self.owning_class = type(obj)

        if self.scalar:
            creator = self.creator and self.creator or self.target_class
            target = getattr(obj, self.target_collection)
            if target is None:
                setattr(obj, self.target_collection, creator(values))
            else:
                self._scalar_set(target, values)
        else:
            proxy = self.__get__(obj, None)
            if proxy is not values:
                proxy.clear()
                self._set(proxy, values)

Comments (7)

  1. Mike Bayer reporter

    found the real issue regarding #2637, it's not the clear(), was a missing backref implementation. The clear() here is still possibly something that can be improved but this is low priority.

  2. Log in to comment