Domanda

Suppose the following models:

class DeltaCheck(models.Model):
    logs = generic.GenericRelation('Log')
    title = models.CharField(max_length=50)
    owner = models.ForeignKey(User)

class Log(models.Model):
    title = models.CharField(max_length=50)

    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

If I create a DeltaCheck and a couple of Logs and then delete the DeltaCheck, the Logs are deleted as well:

In [7]: Log.objects.count()
Out[7]: 10

In [8]: DeltaCheck.objects.get().delete()

In [9]: Log.objects.count()
Out[9]: 0

BUT if I delete the User (the field owner), the DeltaCheck gets deleted BUT not the Logs, look:

In [14]: Log.objects.count()
Out[14]: 10

In [15]: DeltaCheck.objects.get().owner.delete()

In [16]: DeltaCheck.objects.all()
Out[16]: []

In [17]: Log.objects.count()
Out[17]: 10

Why is that? Seems like a bug.

EDIT 1:

Curiously, both pre_delete and post_delete signals are fired in the failing case... What happens in the middle?

EDIT 2:

Ok this is weird as heck. If I define an EMPTY receiver for the pre_delete signal... it works :/ Just added:

@receiver(pre_delete)
def recv(**kwargs):
    pass

And now it works...

È stato utile?

Soluzione

As the bug report states, it was certainly a bug that has now been fixed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top