Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deletion of inherited models #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ron8mcr
Copy link

@ron8mcr ron8mcr commented Dec 27, 2016

As referenced in #13, not all related objects should be deleted.

But I think that ForeignKey should resolve it by itself, using on_delete param. The same applies to OneToOneField.

But there is another case with inherited models.
Consider following case:

class BaseModel(LogicalDeleteModel):
    name = models.CharField(default='Empty name', max_length=256)

class InhertedModel(BaseModel):
    description = models.TextField(default='Some description')

In this case, when the instance of InhertedModel would be deleted, related objects will contain linked the instance of BaseModel and it's delete method will be called. Which collect instance of InhertedModel in related objects and call it's delete method.
So we will have endless recursion.

This commit fixes it

As referenced in pinax#13, not all related objects should be deleted.

But I think that ``ForeignKey`` should resolve it by itself,
using ``on_delete`` param. The same applies to ``OneToOneField``.

But there is another case with inherited models.
Consider following case:

```
class BaseModel(UndeleteBase):
    name = models.CharField(default='Empty name', max_length=256)

class InhertedModel(BaseModel):
    description = models.TextField(default='Some description')
```

In this case, when the instance of ``InhertedModel`` would be deleted,
related objects will contain linked the instance of ``BaseModel``
and it's ``delete`` method will be called. Which collect instance
of ``InhertedModel`` in related objects and call it's ``delete`` method.
So we will have endless recursion.

This commit fixes it
@ron8mcr ron8mcr changed the title Fix deletion of inherted models Fix deletion of inherited models Dec 27, 2016
Previous fix worked just for inherited
models, but fails with models that have
``ForeignKey('self')``. Now it fixed
@ron8mcr
Copy link
Author

ron8mcr commented Jan 26, 2017

Travis checks failed with Django's master branch and seem like issue there, not in commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant