[Django] #33613: manage.py createsuperuser does not validate usernames that use a UniqueConstraint

4 views
Skip to first unread message

Django

unread,
Mar 31, 2022, 6:08:34 AM3/31/22
to django-...@googlegroups.com
#33613: manage.py createsuperuser does not validate usernames that use a
UniqueConstraint
----------------------------------------+------------------------
Reporter: Lucidiot | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
With a custom User model that uses a `UniqueConstraint` instead of
`unique=True`, the `manage.py createsuperuser` command does not validate
usernames at all.

{{{
#!python
class CustomUser(AbstractBaseUser):
custom_username = models.CharField(max_length=255)
USERNAME_FIELD = 'custom_username'

class Meta:
constraints = [
models.UniqueConstraint(fields=['custom_username'],
name='unique_usernames'),
]
}}}

Running `manage.py createsuperuser` to create a user with a username that
already exists then results in an IntegrityError:

{{{
IntegrityError: duplicate key value violates unique constraint
"unique_usernames"
DETAIL: Key (custom_username)=(foo) already exists.
}}}

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

Reply all
Reply to author
Forward
0 new messages