#27807: Overriding username validators doesn't work as documented
-------------------------------------+-------------------------------------
     Reporter:  johnrork             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  contrib.auth         |                  Version:  1.10
     Severity:  Normal               |               Resolution:
     Keywords:  validation auth      |             Triage Stage:  Accepted
  login forms username               |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Jarek Glowacki):

 Just dropping a diff here for failing tests if someone picks this up in
 future.
 Though I'd also support just closing this as a wontfix.
 {{{
 diff --git a/tests/validation/models.py b/tests/validation/models.py
 index e8e18cfbce..1069f5719f 100644
 --- a/tests/validation/models.py
 +++ b/tests/validation/models.py
 @@ -1,5 +1,6 @@
  from datetime import datetime

 +from django.contrib.auth.models import User
  from django.core.exceptions import ValidationError
  from django.db import models

 @@ -134,3 +135,7 @@ assert str(assertion_error) == (
      "Model validation.MultipleAutoFields can't have more than one "
      "auto-generated field."
  )
 +
 +
 +class ShadowUser(User):
 +    username_validator = validate_answer_to_universe
 diff --git a/tests/validation/test_override.py
 b/tests/validation/test_override.py
 new file mode 100644
 index 0000000000..2c0da854bd
 --- /dev/null
 +++ b/tests/validation/test_override.py
 @@ -0,0 +1,13 @@
 +from django.test import SimpleTestCase
 +
 +from .models import ShadowUser
 +
 +
 +class TestUsernameValidatorOverride(SimpleTestCase):
 +    def test_username_validator_override(self):
 +        self.assertEqual(ShadowUser.username_validator.__name__,
 'validate_answer_to_universe')
 +
 +        self.assertCountEqual(
 +            ['validate_answer_to_universe'],
 +            [getattr(v, '__name__', v.__class__.__name__) for v in
 ShadowUser._meta.get_field("username").validators]
 +        )
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/27807#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.83aac51f22d2f258418f4028cb93afa9%40djangoproject.com.

Reply via email to