Honza, I've got a few questions about the use case you mentioned in IRC:
"The use case is that we have a FormField
, that stores text in markup in external Model, and passes rendered text in its clean, then registers the post_save
hook to save the markup somewhere to enable later editing."
You mention that, as shown in the attached tests, that the second receiver doesn't get run or removed and that this causes problems for the next instance that gets saved.
Well, don't you still have a problem if some other thread saves a different instance of the Model before save gets called on the target instance? In this case, the receivers would get called on the different instance, get removed from the post_save hook, then not get called when the target instance is saved. Or do you not care to be thread safe?
Also, what happens if this custom field cleans fine, but the form still had errors in other fields. In this case the receivers are still connected and could cause havoc on the next instance saved.
If all you are doing is registering receivers and then removing them, could you not simply call the receiver functions after you save the instance and not hook them up to the signal at all? For example, in a post_save
method of the field that the form calls after successful validation.