Opened 20 months ago
Last modified 17 months ago
#34542 closed Bug
Required fields allowed to be blank are not accepted non-interactively using createsuperuser — at Version 5
Reported by: | Lantizia | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | dev |
Severity: | Normal | Keywords: | auth createsuperuser superuser email |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
I've only encountered Django once before (installing mailman3), but this time I was trying to install NetBox and I noticed this sentence in their documentation...
"Specifying an email address for the user is not required" (search for that line in the URL below for better context)
https://docs.netbox.dev/en/stable/installation/3-netbox/
According to this line... https://github.com/django/django/blob/main/django/contrib/auth/models.py#L378
The 'email' field is marked as required, but is also marked in a way to allow it to be empty.
This is the section of the code that deals with validating required fields when createsuperuser is called interactively... https://github.com/django/django/blob/main/django/contrib/auth/management/commands/createsuperuser.py#L143
This is the section of the code that deals with validating required fields when createsuperuser is called non-interactively... https://github.com/django/django/blob/main/django/contrib/auth/management/commands/createsuperuser.py#L219
Although required fields are enforced, the non-interactive code doesn't allow for those to be blank, where blank required fields are permitted. I've tried to set a field like 'email' to blank non-interactively but nothing works, for example...
a) just don't set the email field either through an argument or an environment variable... it'll complain it is needed
b) set the email field via a variable as just 'DJANGO_SUPERUSER_EMAIL=' (i.e. setting the variable to null)... it still complains it is needed
c) set the email field via an argument of --email (i.e. double quotes) or --email "" (i.e. double single quotes) or even --email \ (i.e. passing a single space)... it still complains it is needed
Hope this makes sense :)
Change History (5)
comment:1 by , 20 months ago
Description: | modified (diff) |
---|
comment:2 by , 20 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 20 months ago
Hi, then the bug is that noninteractively... it is not allowed to be blank.
comment:4 by , 20 months ago
Resolution: | invalid |
---|---|
Status: | closed → new |
comment:5 by , 20 months ago
Description: | modified (diff) |
---|---|
Summary: | Required fields not enforced when interactively using createsuperuser → Required fields allowed to be blank are not accepted non-interactively using createsuperuser |
Hello! The email field for the provided User class from django.contrib.auth does indeed require the email. But the email is allowed to be the empty string (
blank=True
in the model), so when creating users via a django web form or interactively, one can pass the empty string as value and that is accepted.In summary, the email field is required but it can be blank.