diff --git a/django/db/models/base.py b/django/db/models/base.py index f156643eed..cee5b9a520 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -987,6 +987,8 @@ class Model(six.with_metaclass(ModelBase)): errors = {} if exclude is None: exclude = [] + else: + exclude = list(exclude) try: self.clean_fields(exclude=exclude) diff --git a/tests/validation/__init__.py b/tests/validation/__init__.py index ba35963744..01575c1b10 100644 --- a/tests/validation/__init__.py +++ b/tests/validation/__init__.py @@ -3,9 +3,9 @@ from django.test import TestCase class ValidationTestCase(TestCase): - def assertFailsValidation(self, clean, failed_fields): + def assertFailsValidation(self, clean, failed_fields, **kwargs): with self.assertRaises(ValidationError) as cm: - clean() + clean(**kwargs) self.assertEqual(sorted(failed_fields), sorted(cm.exception.message_dict)) def assertFieldFailsValidationWithMessage(self, clean, field_name, message): diff --git a/tests/validation/tests.py b/tests/validation/tests.py index 7f81cafccf..6122444e3d 100644 --- a/tests/validation/tests.py +++ b/tests/validation/tests.py @@ -59,6 +59,13 @@ class BaseModelValidationTests(ValidationTestCase): mtv = ModelToValidate(number=10, name='Some Name', slug='##invalid##') self.assertFailsValidation(mtv.full_clean, ['slug']) + def test_full_clean_does_not_mutate_exclude(self): + mtv = ModelToValidate(f_with_custom_validator=42) + exclude = ['number'] + self.assertFailsValidation(mtv.full_clean, ['name'], exclude=exclude) + self.assertEqual(len(exclude), 1) + self.assertEqual(exclude[0], 'number') + class ArticleForm(forms.ModelForm): class Meta: