Refs #8760 -- Removed "list" message for ModelMultipleChoiceField per deprecation timeline.

This commit is contained in:
Mariusz Felisiak 2021-01-13 12:29:58 +01:00
parent 1adcf20385
commit bf770cc825
4 changed files with 3 additions and 36 deletions

View File

@ -2,7 +2,6 @@
Helper functions for creating Form classes from Django models Helper functions for creating Form classes from Django models
and database field objects. and database field objects.
""" """
import warnings
from itertools import chain from itertools import chain
from django.core.exceptions import ( from django.core.exceptions import (
@ -15,7 +14,6 @@ from django.forms.utils import ErrorList
from django.forms.widgets import ( from django.forms.widgets import (
HiddenInput, MultipleHiddenInput, RadioSelect, SelectMultiple, HiddenInput, MultipleHiddenInput, RadioSelect, SelectMultiple,
) )
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.text import capfirst, get_text_list from django.utils.text import capfirst, get_text_list
from django.utils.translation import gettext, gettext_lazy as _ from django.utils.translation import gettext, gettext_lazy as _
@ -1313,13 +1311,6 @@ class ModelMultipleChoiceField(ModelChoiceField):
def __init__(self, queryset, **kwargs): def __init__(self, queryset, **kwargs):
super().__init__(queryset, empty_label=None, **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): def to_python(self, value):
if not value: if not value:

View File

@ -1347,10 +1347,6 @@ generating choices. See :ref:`iterating-relationship-choices` for details.
Same as :class:`ModelChoiceField.iterator`. Same as :class:`ModelChoiceField.iterator`.
.. deprecated:: 3.1
The ``list`` message is deprecated, use ``invalid_list`` instead.
.. _iterating-relationship-choices: .. _iterating-relationship-choices:
Iterating relationship choices Iterating relationship choices

View File

@ -301,3 +301,5 @@ to remove usage of these features.
doesn't accept ``None``. doesn't accept ``None``.
* The ``providing_args`` argument for ``django.dispatch.Signal`` is removed. * The ``providing_args`` argument for ``django.dispatch.Signal`` is removed.
* The ``list`` message for ``ModelMultipleChoiceField`` is removed.

View File

@ -8,8 +8,7 @@ from django.forms import (
SplitDateTimeField, TimeField, URLField, utils, SplitDateTimeField, TimeField, URLField, utils,
) )
from django.template import Context, Template from django.template import Context, Template
from django.test import SimpleTestCase, TestCase, ignore_warnings from django.test import SimpleTestCase, TestCase
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from ..models import ChoiceModel from ..models import ChoiceModel
@ -309,24 +308,3 @@ class ModelChoiceFieldErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
self.assertFormErrors(['REQUIRED'], f.clean, '') self.assertFormErrors(['REQUIRED'], f.clean, '')
self.assertFormErrors(['NOT A LIST OF VALUES'], f.clean, '3') self.assertFormErrors(['NOT A LIST OF VALUES'], f.clean, '3')
self.assertFormErrors(['4 IS INVALID CHOICE'], f.clean, ['4']) 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'},
)