Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19925 - Added validation for REQUIRED_FIELDS being a list

Thanks Roman Alexander for the suggestion.
  • Loading branch information...
commit 69373f3420d28597332a72269b5fae721cc6ae19 1 parent 357d62d
@streeter streeter authored timgraham committed
View
1  AUTHORS
@@ -550,6 +550,7 @@ answer newbie questions, and generally made Django that much better:
Thomas Steinacher <http://www.eggdrop.ch/>
Emil Stenström <em@kth.se>
Johan C. Stöver <johan@nilling.nl>
+ Chris Streeter <chris@chrisstreeter.com>
Nowell Strite <http://nowell.strite.org/>
Thomas Stromberg <tstromberg@google.com>
Hannes Struß <x@hannesstruss.de>
View
12 django/contrib/auth/tests/test_custom_user.py
@@ -156,6 +156,18 @@ class Meta:
app_label = 'auth'
+class CustomUserNonListRequiredFields(AbstractBaseUser):
+ "A user with a non-list REQUIRED_FIELDS"
+ username = models.CharField(max_length=30, unique=True)
+ date_of_birth = models.DateField()
+
+ USERNAME_FIELD = 'username'
+ REQUIRED_FIELDS = 'date_of_birth'
+
+ class Meta:
+ app_label = 'auth'
+
+
class CustomUserBadRequiredFields(AbstractBaseUser):
"A user with a non-unique username"
username = models.CharField(max_length=30, unique=True)
View
7 django/contrib/auth/tests/test_management.py
@@ -174,6 +174,13 @@ def test_swappable_user_missing_required_field(self):
class CustomUserModelValidationTestCase(TestCase):
+ @override_settings(AUTH_USER_MODEL='auth.CustomUserNonListRequiredFields')
+ def test_required_fields_is_list(self):
+ "REQUIRED_FIELDS should be a list."
+ new_io = StringIO()
+ get_validation_errors(new_io, get_app('auth'))
+ self.assertIn("The REQUIRED_FIELDS must be a list or tuple.", new_io.getvalue())
+
@override_settings(AUTH_USER_MODEL='auth.CustomUserBadRequiredFields')
def test_username_not_in_required_fields(self):
"USERNAME_FIELD should not appear in REQUIRED_FIELDS."
View
4 django/core/management/validation.py
@@ -51,6 +51,10 @@ def get_validation_errors(outfile, app=None):
# If this is the current User model, check known validation problems with User models
if settings.AUTH_USER_MODEL == '%s.%s' % (opts.app_label, opts.object_name):
+ # Check that REQUIRED_FIELDS is a list
+ if not isinstance(cls.REQUIRED_FIELDS, (list, tuple)):
+ e.add(opts, 'The REQUIRED_FIELDS must be a list or tuple.')
+
# Check that the USERNAME FIELD isn't included in REQUIRED_FIELDS.
if cls.USERNAME_FIELD in cls.REQUIRED_FIELDS:
e.add(opts, 'The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.')
Please sign in to comment.
Something went wrong with that request. Please try again.