[Zope-dev] Be careful when using manage_beforeDelete

Robert Leftwich robert@leftfieldcorp.com
Sat, 25 Sep 1999 10:54:30 +1000


I'd like to give everyone a warning about the use of the
manage_beforeDelete protocol. If you override this function to perform
additional clean-up/referential integrity type tasks when an object is
deleted from a folder (as you should) be warned that the implementation
of manage_renameObject deletes and then adds the object with the new
name. Obviously, this calls the manage_beforeDelete function with the
result that the renamed object will not be the same as the original
object depending on what your manage_beforeDelete does.

For example, assume you have implemented a simple calendar product that
interacts with a contact list to enable you to schedule calls to a
particular contact and that as part of deleting a contact, you remove
all scheduled items for that contact (as you must, to avoid orphan
schedule objects). If you then rename the contact using
manage_renameObject either from the management screens or
programmatically, you'll end up with a contact with no associated
schedules.

A similar issue exists when pasting an object via manage_pasteObject and
when using WebDav to move an object.

My current workaround involves overriding _notifyOfCopyTo, setting an
internal flag which is checked in manage_beforeDelete before any cleanup
is done and reset on exit from this function. However, I believe
_notifyOfCopyTo is being replaced by manage_afterClone as
_notifyOfCopyTo is not called in the WebDav code but it is in the
CopySupport code.

This solution should probably be generalised and incorporated into Zope
so that this issue can be avoided.
Does anyone have any thoughts on a general solution? Maybe the
combination of manage_beforeDelete, manage_afterAdd and
manage_afterClone is insufficient and needs to be extended either by
additional parameters or function calls.

Robert Leftwich