From 7a908747a52f7cc12d7006058daad6a6c973c462 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 20 Oct 2012 11:51:15 +0800 Subject: [PATCH] Fixed #19150 -- Added validation for USERNAME_FIELD being included in REQUIRED_FIELDS. Thanks to Chris Pagnutti for the suggestion. --- django/core/management/validation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/django/core/management/validation.py b/django/core/management/validation.py index a9b0c26062..957a712b72 100644 --- a/django/core/management/validation.py +++ b/django/core/management/validation.py @@ -1,5 +1,6 @@ import sys +from django.conf import settings from django.core.management.color import color_style from django.utils.encoding import force_str from django.utils.itercompat import is_iterable @@ -48,6 +49,12 @@ def get_validation_errors(outfile, app=None): # No need to perform any other validation checks on a swapped model. continue + # 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 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.') + # Model isn't swapped; do field-specific validation. for f in opts.local_fields: if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':