[Django] #31123: remove_stale_contenttypes doesn't remove entries for stale apps

32 views
Skip to first unread message

Django

unread,
Dec 26, 2019, 4:21:34 PM12/26/19
to django-...@googlegroups.com
#31123: remove_stale_contenttypes doesn't remove entries for stale apps
------------------------------------------------+------------------------
Reporter: Gowtham Kommineni | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
remove_stale_contenttypes only removes stale content types for stale
models in installed apps. It doesn't remove stale content types whose app
was either removed or renamed.

Test:
Comment out the line that limits the available apps.
# Speed up tests by avoiding retrieving ContentTypes for all test apps.
# available_apps = ['contenttypes_tests', 'no_models',
'django.contrib.contenttypes']

def test_contenttypes_removed_for_apps_not_in_installed_apps(self):
ContentType.objects.create(app_label='stale_app', model='Fake')
with mock.patch('builtins.input', return_value='yes'),
captured_stdout() as stdout:
call_command('remove_stale_contenttypes', verbosity=2)
self.assertIn("Deleting stale content type 'stale_app | Fake'",
stdout.getvalue())
self.assertEqual(ContentType.objects.count(), self.before_count)

--
Ticket URL: <https://code.djangoproject.com/ticket/31123>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 30, 2019, 4:36:13 AM12/30/19
to django-...@googlegroups.com
#31123: remove_stale_contenttypes doesn't remove entries for nonexistent apps.
-------------------------------------+-------------------------------------

Reporter: Gowtham Kommineni | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 3.0
contrib.contenttypes |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix


Comment:

I don't think that `remove_stale_contenttypes` should remove content types
for nonexistent apps. We don't automatically remove models for nonexistent
apps and I don't think we should do this with content types. This can also
cause a data loss for a custom content types (not related to real apps).
You can start a discussion on DevelopersMailingList if you don't agree.

--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:1>

Django

unread,
Jan 29, 2020, 11:31:04 AM1/29/20
to django-...@googlegroups.com
#31123: Add option to remove_stale_contenttypes to remove entries for nonexistent
apps.
--------------------------------------+------------------------------------

Reporter: Gowtham Kommineni | Owner: nobody
Type: New feature | Status: new
Component: contrib.contenttypes | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by felixxm):

* status: closed => new
* type: Bug => New feature
* version: 3.0 => master
* has_patch: 1 => 0
* resolution: wontfix =>
* stage: Unreviewed => Accepted


Old description:

> remove_stale_contenttypes only removes stale content types for stale
> models in installed apps. It doesn't remove stale content types whose app
> was either removed or renamed.
>
> Test:
> Comment out the line that limits the available apps.
> # Speed up tests by avoiding retrieving ContentTypes for all test apps.
> # available_apps = ['contenttypes_tests', 'no_models',
> 'django.contrib.contenttypes']
>
> def test_contenttypes_removed_for_apps_not_in_installed_apps(self):
> ContentType.objects.create(app_label='stale_app', model='Fake')
> with mock.patch('builtins.input', return_value='yes'),
> captured_stdout() as stdout:
> call_command('remove_stale_contenttypes', verbosity=2)
> self.assertIn("Deleting stale content type 'stale_app | Fake'",
> stdout.getvalue())
> self.assertEqual(ContentType.objects.count(), self.before_count)

New description:

Add an option (disabled by default) to `remove_stale_contenttypes` command
to remove entries also for nonexistent apps.

Based on
[https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic
/django-developers/0WrbU_Kc2Z0 discussion].

--

Comment:

Accepted based on
[https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic
/django-developers/0WrbU_Kc2Z0 discussion] .

--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:2>

Django

unread,
Mar 11, 2020, 4:51:46 PM3/11/20
to django-...@googlegroups.com
#31123: Add option to remove_stale_contenttypes to remove entries for nonexistent
apps.
--------------------------------------+------------------------------------
Reporter: Gowtham Kommineni | Owner: nobody
Type: New feature | Status: new
Component: contrib.contenttypes | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Javier Buzzi):

* has_patch: 0 => 1


Old description:

> Add an option (disabled by default) to `remove_stale_contenttypes`
> command to remove entries also for nonexistent apps.
>
> Based on
> [https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic
> /django-developers/0WrbU_Kc2Z0 discussion].

New description:

Add an option (disabled by default) to `remove_stale_contenttypes` command
to remove entries also for nonexistent apps.

Based on
[https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic
/django-developers/0WrbU_Kc2Z0 discussion].

[https://github.com/django/django/pull/12558 PR]

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:3>

Django

unread,
Mar 18, 2020, 6:54:11 AM3/18/20
to django-...@googlegroups.com
#31123: Add option to remove_stale_contenttypes to remove entries for nonexistent
apps.
-------------------------------------+-------------------------------------
Reporter: Gowtham Kommineni | Owner: Gowtham
| Kommineni
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* owner: nobody => Gowtham Kommineni
* needs_better_patch: 0 => 1
* status: new => assigned
* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:4>

Django

unread,
Mar 19, 2020, 5:40:51 AM3/19/20
to django-...@googlegroups.com
#31123: Add option to remove_stale_contenttypes to remove entries for nonexistent
apps.
-------------------------------------+-------------------------------------
Reporter: Gowtham Kommineni | Owner: Gowtham
| Kommineni
Type: New feature | Status: assigned
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:5>

Django

unread,
Mar 19, 2020, 7:16:30 AM3/19/20
to django-...@googlegroups.com
#31123: Add option to remove_stale_contenttypes to remove entries for nonexistent
apps.
-------------------------------------+-------------------------------------
Reporter: Gowtham Kommineni | Owner: Gowtham
| Kommineni
Type: New feature | Status: closed
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"142ab6846ac09d6d401e26fc8b6b988a583ac0f5" 142ab684]:
{{{
#!CommitTicketReference repository=""
revision="142ab6846ac09d6d401e26fc8b6b988a583ac0f5"
Fixed #31123 -- Added --include-stale-apps option to the
remove_stale_contenttypes management command.

Co-Authored-By: Javier Buzzi <buzzi....@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:6>

Django

unread,
Aug 17, 2025, 1:11:15 AM8/17/25
to django-...@googlegroups.com
#31123: Add option to remove_stale_contenttypes to remove entries for nonexistent
apps.
-------------------------------------+-------------------------------------
Reporter: Gowtham Kommineni | Owner: Gowtham
| Kommineni
Type: New feature | Status: closed
Component: | Version: dev
contrib.contenttypes |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8b229b4dbb6db08428348aeb7e5a536b64cf8ed8" 8b229b4d]:
{{{#!CommitTicketReference repository=""
revision="8b229b4dbb6db08428348aeb7e5a536b64cf8ed8"
Refs #31123 -- Simplified create_contentypes().

Since 142ab6846ac09d6d401e26fc8b6b988a583ac0f5
get_contenttypes_and_models() function was only used in this module and
we only needed the model names, not the content type objects themselves.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:7>
Reply all
Reply to author
Forward
0 new messages