Re: [Django] #36225: USERNAME_FIELD must be unique in order to use createsuperuser command

14 views
Skip to first unread message

Django

unread,
Mar 15, 2025, 9:48:09 AMMar 15
to django-...@googlegroups.com
#36225: USERNAME_FIELD must be unique in order to use createsuperuser command
-------------------------------------+-------------------------------------
Reporter: Jonas Dittrich | Owner: Spencer
Type: | Barriball
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Spencer Barriball):

* owner: (none) => Spencer Barriball
* status: new => assigned

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

Django

unread,
Mar 15, 2025, 11:49:33 AMMar 15
to django-...@googlegroups.com
#36225: USERNAME_FIELD must be unique in order to use createsuperuser command
-------------------------------------+-------------------------------------
Reporter: Jonas Dittrich | Owner: Spencer
Type: | Barriball
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

Spencer, it's great that you're interested on working on this ticket but
it was accepted on the basis that the documentation stating that the
documentation must be adjusted not that the `create_superuser` command
should be adjusted.
--
Ticket URL: <https://code.djangoproject.com/ticket/36225#comment:5>

Django

unread,
Mar 15, 2025, 12:05:37 PMMar 15
to django-...@googlegroups.com
#36225: USERNAME_FIELD must be unique in order to use createsuperuser command
-------------------------------------+-------------------------------------
Reporter: Jonas Dittrich | Owner: Spencer
Type: | Barriball
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Spencer Barriball):

Thanks for the clarification, Simon. I initially interpreted the ticket as
a code adjustment rather than just a documentation update. Since it's a
documentation tweak, would you like me to update the relevant part of the
USERNAME_FIELD docs and submit a PR for that instead?

On a side note, at least I got everything up and running to be able to
contribute code in the future!
--
Ticket URL: <https://code.djangoproject.com/ticket/36225#comment:6>

Django

unread,
Sep 4, 2025, 7:20:22 AM (3 days ago) Sep 4
to django-...@googlegroups.com
#36225: USERNAME_FIELD must be unique in order to use createsuperuser command
-------------------------------------+-------------------------------------
Reporter: Jonas Dittrich | Owner:
Type: | Abderrahmane MELEK
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Abderrahmane MELEK):

* has_patch: 0 => 1
* owner: Spencer Barriball => Abderrahmane MELEK

--
Ticket URL: <https://code.djangoproject.com/ticket/36225#comment:7>

Django

unread,
Sep 4, 2025, 3:10:13 PM (3 days ago) Sep 4
to django-...@googlegroups.com
#36225: USERNAME_FIELD must be unique in order to use createsuperuser command
-------------------------------------+-------------------------------------
Reporter: Jonas Dittrich | Owner:
Type: | Abderrahmane MELEK
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

The plan from comment:3 to tweak the docs gives me pause, since this use
case was explicitly
[https://github.com/django/django/blob/4e7a991c12a113229e0927974d3bf94ea04eecf6/tests/auth_tests/models/invalid_models.py#L5
tested] and added in #24910.

From my reading of the forum post, the two sharp edges that came up for
the implementer were:
- reimplementing `AbstractBaseUser` from scratch to avoid having to `del
AbstractBaseUser.natural_key` to support serialization
- createsuperuser's username validation not being aware of `null=True,
distinct=True` username fields

We could tweak the docs instead to explain that `natural_key` must be
overridden on the model. The use case for nullable usernames and the
attendant weirdness around having to override `get_by_natural_key` on the
manager doesn't seem worth documenting to me: it could just be implicit
from the advice to "override".
--
Ticket URL: <https://code.djangoproject.com/ticket/36225#comment:8>

Django

unread,
Sep 4, 2025, 3:12:48 PM (3 days ago) Sep 4
to django-...@googlegroups.com
#36225: USERNAME_FIELD must be unique in order to use createsuperuser command
-------------------------------------+-------------------------------------
Reporter: Jonas Dittrich | Owner:
Type: | Abderrahmane MELEK
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36225#comment:9>
Reply all
Reply to author
Forward
0 new messages