Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19150 -- Added validation for USERNAME_FIELD being included in…

… REQUIRED_FIELDS.

Thanks to Chris Pagnutti for the suggestion.
  • Loading branch information...
commit 7a908747a52f7cc12d7006058daad6a6c973c462 1 parent 04b53eb
Russell Keith-Magee authored October 20, 2012

Showing 1 changed file with 7 additions and 0 deletions. Show diff stats Hide diff stats

  1. 7  django/core/management/validation.py
7  django/core/management/validation.py
... ...
@@ -1,5 +1,6 @@
1 1
 import sys
2 2
 
  3
+from django.conf import settings
3 4
 from django.core.management.color import color_style
4 5
 from django.utils.encoding import force_str
5 6
 from django.utils.itercompat import is_iterable
@@ -48,6 +49,12 @@ def get_validation_errors(outfile, app=None):
48 49
             # No need to perform any other validation checks on a swapped model.
49 50
             continue
50 51
 
  52
+        # This is the current User model. Check known validation problems with User models
  53
+        if settings.AUTH_USER_MODEL == '%s.%s' % (opts.app_label, opts.object_name):
  54
+            # Check that the USERNAME FIELD isn't included in REQUIRED_FIELDS.
  55
+            if cls.USERNAME_FIELD in cls.REQUIRED_FIELDS:
  56
+                e.add(opts, 'The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.')
  57
+
51 58
         # Model isn't swapped; do field-specific validation.
52 59
         for f in opts.local_fields:
53 60
             if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':

0 notes on commit 7a90874

Please sign in to comment.
Something went wrong with that request. Please try again.