Opened 10 years ago
Closed 10 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: | dev |
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 |
Description
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 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
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 by , 10 years ago
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 by , 10 years ago
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.
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.