Opened 4 years ago

Closed 4 years ago

#29556 closed Bug (fixed)

remove_stale_contenttypes --noinput should delete stale content types

Reported by: Jon Dufresne Owned by: nobody
Component: contrib.contenttypes Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I recently noticed that remove_stale_contenttypes --noinput does not delete stale content types. It simply does nothing and returns, effectively making the command a noop. I had been absentmindedly using this command for months not realizing it wasn't useful. To use this command to delete content types, one must run the command in interactive mode and answer "yes" at the prompt. This makes it difficult to use when managing a large number of Django sites where it is impractical to run interactive commands.

The previous post_migrate signal, when combined with --noinput, did not delete content types due to data loss concerns. However, now that remove_stale_contenttypes is a standalone management command, I think the data ramifications are much more clear and less likely to cause unwanted data loss.

I suggest one the following:

  • (My preferred) Change remove_stale_contenttypes --noinput to remove stale content types instead of doing nothing. I think this is a more intuitive behavior given the arguments. The combination of arguments would stop being a noop and provide useful behavior to projects managing a large number of Django sites. However, I recognize this has some backwards compatibility concerns. The argument would change from doing nothing to deleting database records.
  • Add a new argument --force that would assume the answer "yes" for all prompts. I think this is less optimal as it introduces an argument that doesn't need to exist if we could modify the behavior of --noinput.

If the backward compatibility concerns are too much, perhaps it could be introduced in stages:

Next release:

  • Issue a deprecation warning when using remove_stale_contenttypes --noinput, state that it will delete content types in a future version.
  • Add --force arguments so project admins can delete stale content types in a non-interactive fashion.

After a deprecation period:

  • Change remove_stale_contenttypes --noinput to delete content types.
  • Deprecate, and eventually remove, --force.

Prior tickets to consider:

  • #24865 -- Add a management command to remove stale content types
  • #25036 -- migrate --noinput does not delete stale content types (refers to old post_migrate signal)

Code of remove_stale_contenttypes showing that it is a noop:

Change History (3)

comment:1 Changed 4 years ago by Jon Dufresne

Has patch: set

comment:2 Changed 4 years ago by Tim Graham

Summary: remove_stale_contenttypes --noinput should non-interactively delete stale content typesremove_stale_contenttypes --noinput should delete stale content types
Triage Stage: UnreviewedReady for checkin
Type: New featureBug

comment:3 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 08ebed5e:

Fixed #29556 -- Made 'remove_stale_contenttypes --noinput' delete content types.

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