Opened 4 years ago

Closed 4 years ago

#24546 closed New feature (duplicate)

Deletion of stale content types during migrate should show cascade

Reported by: Aymeric Augustin Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When deleting stale content-types, the migrate command says:

The following content types are stale and need to be deleted:

    auth | group_permissions

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: yes

At this point, the user has no way to tell whether they should answer 'yes' or 'no'.

Usually they will type 'no' until they get bored, say a quick prayer and type 'yes'.

Django contains infrastructure to determine how many objects will be deleted.

>>> ct = ContentType.objects.get(app_label='auth', model='group_permissions')
>>> collector = NestedObjects(using=DEFAULT_DB_ALIAS)
>>> collector.collect([ct])
>>> print(collector.nested())
[<ContentType: group-permission relationship>]

It would be helpful to display the list of objects that will be deleted or at least the number of objects.

If the collector returns just the original object, perhaps migrate could even proceed with the deletion without asking.

Change History (5)

comment:1 Changed 4 years ago by Sasha Romijn

Triage Stage: UnreviewedAccepted

Yes, this would be great. I ran into this just yesterday, and indeed answered no because I just wasn't sure enough. I'm not sure whether automatic deletion if there are no other objects is good - somehow it seems to me that migrate should not automatically delete such data even if it seems harmless.

comment:2 Changed 4 years ago by Aymeric Augustin

The argument for deleting automatically is that content types are created automatically.

They're mostly a technicality of the admin's history log, not a user-visible feature.

comment:3 Changed 4 years ago by Carl Meyer

I _wish_ content types were an implementation detail (or didn't exist at all), but unfortunately I don't think that's the case. They are a core part of the GenericForeignKey, which is very much a user-visible feature. And the ContentType model itself is documented as a user-visible feature, as well, so it would be entirely reasonable for people to have cascading FKs pointing to ContentType, and that would be within public documented API.

comment:4 Changed 4 years ago by Aymeric Augustin

s/feature/footgun/ ;-)

In case I wasn't clear enough, I consider automatic deletion acceptable only when there are no related objects that the cascade would delete, not even admin log entries.

comment:5 Changed 4 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

Dup of #18682.

Note: See TracTickets for help on using tickets.
Back to Top