From bf770cc825f1af294b3b2853b39b5b161b6a056f Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 13 Jan 2021 12:29:58 +0100 Subject: [PATCH] Refs #8760 -- Removed "list" message for ModelMultipleChoiceField per deprecation timeline. --- django/forms/models.py | 9 ------- docs/ref/forms/fields.txt | 4 ---- docs/releases/4.0.txt | 2 ++ .../forms_tests/tests/test_error_messages.py | 24 +------------------ 4 files changed, 3 insertions(+), 36 deletions(-) diff --git a/django/forms/models.py b/django/forms/models.py index 0591cdf338..422bc5d178 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -2,7 +2,6 @@ Helper functions for creating Form classes from Django models and database field objects. """ -import warnings from itertools import chain from django.core.exceptions import ( @@ -15,7 +14,6 @@ from django.forms.utils import ErrorList from django.forms.widgets import ( HiddenInput, MultipleHiddenInput, RadioSelect, SelectMultiple, ) -from django.utils.deprecation import RemovedInDjango40Warning from django.utils.text import capfirst, get_text_list from django.utils.translation import gettext, gettext_lazy as _ @@ -1313,13 +1311,6 @@ class ModelMultipleChoiceField(ModelChoiceField): def __init__(self, queryset, **kwargs): super().__init__(queryset, empty_label=None, **kwargs) - if self.error_messages.get('list') is not None: - warnings.warn( - "The 'list' error message key is deprecated in favor of " - "'invalid_list'.", - RemovedInDjango40Warning, stacklevel=2, - ) - self.error_messages['invalid_list'] = self.error_messages['list'] def to_python(self, value): if not value: diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index 52ab59e626..b13af1a270 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -1347,10 +1347,6 @@ generating choices. See :ref:`iterating-relationship-choices` for details. Same as :class:`ModelChoiceField.iterator`. -.. deprecated:: 3.1 - - The ``list`` message is deprecated, use ``invalid_list`` instead. - .. _iterating-relationship-choices: Iterating relationship choices diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index c71d66f4a8..d2e18ee078 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -301,3 +301,5 @@ to remove usage of these features. doesn't accept ``None``. * The ``providing_args`` argument for ``django.dispatch.Signal`` is removed. + +* The ``list`` message for ``ModelMultipleChoiceField`` is removed. diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py index d60acc1daa..1a6d1386c3 100644 --- a/tests/forms_tests/tests/test_error_messages.py +++ b/tests/forms_tests/tests/test_error_messages.py @@ -8,8 +8,7 @@ from django.forms import ( SplitDateTimeField, TimeField, URLField, utils, ) from django.template import Context, Template -from django.test import SimpleTestCase, TestCase, ignore_warnings -from django.utils.deprecation import RemovedInDjango40Warning +from django.test import SimpleTestCase, TestCase from django.utils.safestring import mark_safe from ..models import ChoiceModel @@ -309,24 +308,3 @@ class ModelChoiceFieldErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): self.assertFormErrors(['REQUIRED'], f.clean, '') self.assertFormErrors(['NOT A LIST OF VALUES'], f.clean, '3') self.assertFormErrors(['4 IS INVALID CHOICE'], f.clean, ['4']) - - -class DeprecationTests(TestCase, AssertFormErrorsMixin): - @ignore_warnings(category=RemovedInDjango40Warning) - def test_list_error_message(self): - f = ModelMultipleChoiceField( - queryset=ChoiceModel.objects.all(), - error_messages={'list': 'NOT A LIST OF VALUES'}, - ) - self.assertFormErrors(['NOT A LIST OF VALUES'], f.clean, '3') - - def test_list_error_message_warning(self): - msg = ( - "The 'list' error message key is deprecated in favor of " - "'invalid_list'." - ) - with self.assertRaisesMessage(RemovedInDjango40Warning, msg): - ModelMultipleChoiceField( - queryset=ChoiceModel.objects.all(), - error_messages={'list': 'NOT A LIST OF VALUES'}, - )