#34542: Required fields allowed to be blank are not accepted non-interactively
using createsuperuser
-------------------------------------+-------------------------------------
     Reporter:  Lantizia             |                    Owner:  Anvansh
                                     |  Singh
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.auth         |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:  auth                 |             Triage Stage:  Accepted
  createsuperuser superuser email    |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Mateusz Więckowski):

 Replying to [comment:21 Lufafa Joshua]:
 >
 > Replying to [# Mateusz Więckowski]:
 > >I'm using cmd. I did some changes to "non-interactive" part in Django's
 createsuperuser.py
 > >It's rather quick, so you could do it yourself and check:
 > >Move this line:
 >
 >​https://github.com/django/django/blob/main/django/contrib/auth/management/commands/createsuperuser.py#L226
 > >above the if statement at the line 222
 > >In the if itself add the following:
 > >{{{
 > >if field.blank and options[field_name] is not None:
 >     >continue
 > >}}}
 > Hey,  Considering your approach, instead of using:
 >
 > {{{
 > if field.blank and options[field_name] is not None:
 >     continue
 > }}}
 > I have used
 > {{{
 > if field.blank:
 >     continue
 > }}}
 > and it seems to bypass the exception if the field is allowed to be blank
 while using environment variable or {{{--noinput}}}
 >
 >
 >
 >
 >
 >
 Hey, that was my initial approach, but it creates unwanted behavior that
 is described in comments: #comment:13 and #comment:14.

 I've also found that this:

 {{{
 if field.blank and options[field_name] is not None:
     continue
 }}}
 Doesn't work for all cases when setting DJANGO_SUPERUSER_EMAIL.

 My current approach looks like this and works for all cases I could've
 found.
 {{{
 if not value:
     if (field.blank and
             (options[field_name] is not None or
                 os.environ.get(env_var) is not None)):
         continue
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34542#comment:22>
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/010701898d9e1f2b-78d6593b-cd24-49a1-aca6-4af22af8470f-000000%40eu-central-1.amazonses.com.

Reply via email to