Skip to content

Many to many relation does not respect softdeletion #1

@basask

Description

@basask

The problem seems to be in many to many scenarios.
Below a snippet on how to reproduce (untested)

# models
from softdelete.models import SoftDeleteModel

class ModelA(SoftDeleteModel):
    name = models.CharField(max_length=16)

class ModelB(SoftDeleteModel):
    name = models.CharField(max_length=16)

class M2M(SoftDeleteModel):
    left = model.ForeignKey(ModelA, related_name='right')
    right = model.ForeignKey(ModelB, related_name='left')
# test
mA = ModelA.objects.create(name='A')
mB = ModelB.objects.create(name='B')
M2M.objects.create(left=mA, right=mB)

mB.objects.filter(left__left__name='A').count()
# Thats ok. Only one instance found here

M2M.objects.all().delete()

mB.objects.filter(left__left__name='A').count()
# Still finding objects when should be hiding through softdelete

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions