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.
* 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>
* 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>
* 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>
* 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>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31123#comment:5>
* 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>