On Jan 28, 2014, at 11:27 AM, Erkan Özgür Yılmaz <[email protected]> wrote:

> Hi everybody,
> 
> I'm trying to use Association Proxy in one of my classes relation to itself. 
> I've got a Task class and Tasks can be dependent to each other, and I've also 
> wanted to store the dependency type ('start-to-start', 'start-to-end' etc.), 
> so AssociationProxy was the way I've gone. Any way my problem is with events.
> 
> So, TaskC depends both to TaskA and TaskB. When I set taskC.depends to [] the 
> remove event successfully triggered, and the 
> Task.update_status_with_dependent_statuses() method is run. And at the end 
> taskC.depends list is [].
> 
> The problem is; even when the second event triggered I still see [TaskA, 
> TaskB] in task.depends, where it should at least be [TaskB] in second run. 
> Therefore the update_status_with_dependent_statuses() method always sees some 
> elements in self.depends and is not able to set the status to RTS.
> 
> Is that making sense? Am I missing something in the documentation?

the documentation is still missing a pretty important note which is that the 
attribute events fire off *before* the actual mutation takes place.  So in your 
event, “self.depends” is still populated.

We haven’t produced a decent solution to the “no events *after* the fact” 
issue; to add event dispatchers for “after” mutation corresponding to every 
“before” mutation would add a significant amount of function calls to every 
collection mutation and attribute set operation, and as long as cPython is 
still the standard interpreter (as opposed to Pypy, which solves this issue 
entirely) the area of attribute mutation remains a major performance bottleneck 
even without more function calls being added.   We’d have to figure out a way 
to organize the (already pretty dense) code to support event handlers on both 
sides without adding major new overhead.

For the time being you’d need to have your event handler be sensitive to the 
fact that the operation is a “remove”, and to anticipate the state that you’re 
responding towards.    That or, create your own collection classes - such as 
subclassing the collection implementation used by the “depends” association 
proxy.


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to