On Thu, Nov 26, 2009 at 12:04 AM, Johannes Dollinger
<
johannes....@einfallsreich.net> wrote:
> QuerySet.delete() currently sets the primary key and all nullable
> foreign keys (to deleted objects) of instances passed to signal
> handlers to None. No cache is updated.
>
> Model.delete() will do the same, but as these instances are collected
> by traversing related object descriptors all reverse o2o field caches
> will be updated.
Are you sure there is a discrepancy here?
ModelBase.delete() creates a CollectedObjects() structure, then
invokes self._collect_sub_objects() to populate it. It then invokes
delete_objects() to delete the objects.
QuerySet.delete() creates a CollectedObjects() structure, then invokes
obj._collect_sub_objects() on each of the objects in the queryset to
populate. It then invokes delete_objects() to delete the objects.
As far as I can make out, both populate the object caches the same way.
> Is this an accidental side effect or desired behavior?
If you are deleting a single object X, X.delete() deletes the object,
so the values in the cache are irrelevant. Similarly, if you delete a
queryset Y, all the items in Y will be deleted, and all the values in
the cache will be irrelevant.
In the case of an object Z that points at X (or an object in Y), but
doesn't result in a cacscading delete, the cache in Z should be
cleared. This is already done for nullable keys; I imagine your code
will need to implement something similar to handle non-cascading
cases.
Yours,
Russ Magee %-)