Skip to content

Issue with .delete(keep_parents=True) #645

@Danfs64

Description

@Danfs64

If we have a model structure like:

from polymorphic.models import PolymorphicModel

class Project(PolymorphicModel):
    topic = models.CharField(max_length=30)

class ArtProject(Project):
    artist = models.CharField(max_length=30)

and populate it a little, if we choose to delete an ArtProject, but keep the underlaying Project intact, we would use something like:

ArtProject.objects.first().delete(keep_parents=True)

This will delete only the ArtProject row on the database, keeping the Project row intact, but if we run Project.objects.all() we will not see the project, even if it clearly is there on the DB. I imagine this has something to do with the fact that, when a .delete(keep_parents=True) is run, the polymorphic_ctype_id still points to, in this case, ArtProject, instead of being updated to the parent Model

If we instead run Project.objects.non_polymorphic().all(), we will see the Project on the returned Queryset.

References:

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions