From 1cb495074f6d983096a015736fed16176588cd33 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 16 Sep 2021 08:23:46 +0200 Subject: [PATCH] Refs #31546 -- Removed support for boolean values in Command.requires_system_checks. Per deprecation timeline. --- django/core/management/base.py | 10 -------- docs/releases/4.1.txt | 3 +++ tests/user_commands/tests.py | 45 +--------------------------------- 3 files changed, 4 insertions(+), 54 deletions(-) diff --git a/django/core/management/base.py b/django/core/management/base.py index 2044b857540..857a77da5ac 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -5,7 +5,6 @@ be executed through ``django-admin`` or ``manage.py``). import argparse import os import sys -import warnings from argparse import ArgumentParser, HelpFormatter from io import TextIOBase @@ -14,7 +13,6 @@ from django.core import checks from django.core.exceptions import ImproperlyConfigured from django.core.management.color import color_style, no_style from django.db import DEFAULT_DB_ALIAS, connections -from django.utils.deprecation import RemovedInDjango41Warning ALL_CHECKS = '__all__' @@ -252,14 +250,6 @@ class BaseCommand: else: self.style = color_style(force_color) self.stderr.style_func = self.style.ERROR - if self.requires_system_checks in [False, True]: - warnings.warn( - "Using a boolean value for requires_system_checks is " - "deprecated. Use '__all__' instead of True, and [] (an empty " - "list) instead of False.", - RemovedInDjango41Warning, - ) - self.requires_system_checks = ALL_CHECKS if self.requires_system_checks else [] if ( not isinstance(self.requires_system_checks, (list, tuple)) and self.requires_system_checks != ALL_CHECKS diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index bf3f3a848fa..96ac8cc19da 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -249,3 +249,6 @@ to remove usage of these features. * Support for assigning objects which don't support creating deep copies with ``copy.deepcopy()`` to class attributes in ``TestCase.setUpTestData()`` is removed. + +* Support for using a boolean value in + :attr:`.BaseCommand.requires_system_checks` is removed. diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index 60cfe86b3d8..d3afb697bb9 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -14,9 +14,8 @@ from django.core.management.utils import ( ) from django.db import connection from django.test import SimpleTestCase, override_settings -from django.test.utils import captured_stderr, extend_sys_path, ignore_warnings +from django.test.utils import captured_stderr, extend_sys_path from django.utils import translation -from django.utils.deprecation import RemovedInDjango41Warning from .management.commands import dance @@ -422,45 +421,3 @@ class UtilsTests(SimpleTestCase): def test_normalize_path_patterns_truncates_wildcard_base(self): expected = [os.path.normcase(p) for p in ['foo/bar', 'bar/*/']] self.assertEqual(normalize_path_patterns(['foo/bar/*', 'bar/*/']), expected) - - -class DeprecationTests(SimpleTestCase): - def test_requires_system_checks_warning(self): - class Command(BaseCommand): - pass - - msg = ( - "Using a boolean value for requires_system_checks is deprecated. " - "Use '__all__' instead of True, and [] (an empty list) instead of " - "False." - ) - for value in [False, True]: - Command.requires_system_checks = value - with self.assertRaisesMessage(RemovedInDjango41Warning, msg): - Command() - - @ignore_warnings(category=RemovedInDjango41Warning) - def test_requires_system_checks_true(self): - class Command(BaseCommand): - requires_system_checks = True - - def handle(self, *args, **options): - pass - - command = Command() - with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check: - management.call_command(command, skip_checks=False) - mocked_check.assert_called_once_with() - - @ignore_warnings(category=RemovedInDjango41Warning) - def test_requires_system_checks_false(self): - class Command(BaseCommand): - requires_system_checks = False - - def handle(self, *args, **options): - pass - - command = Command() - with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check: - management.call_command(command) - self.assertIs(mocked_check.called, False)