#33151: Super user creation always raises an error in non-interactive mode when 
on
required field is a ForeignKey
--------------------------------------------+------------------------
               Reporter:  Christophe Henry  |          Owner:  nobody
                   Type:  Bug               |         Status:  new
              Component:  contrib.auth      |        Version:  3.1
               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                 |
--------------------------------------------+------------------------
 #21755 added `ForeignKey` support to `REQUIRED_FIELDS` in
 `createsuperuser` command but this support is not working in non-
 interactive mode.

 The buggy line is
 
[https://github.com/django/django/blob/main/django/contrib/auth/management/commands/createsuperuser.py#L187
 this line]. If `value` is an integer, `field.clean()` simply returns it
 after validation while
 
[https://github.com/django/django/blob/main/django/contrib/auth/management/commands/createsuperuser.py#L189
 `create_superuser(**user_data)`] on the next line would expect a model
 instance for the `ForeignKey` field.

 If you go one step further and override `createsuperuser` to pass an
 instance of the model, then `field.clean()` raises an error because
 
[https://github.com/django/django/blob/main/django/db/models/fields/__init__.py#L670
 `ForeignKey.to_python()`] expects an integer.

 There may be the same problem with `ManyToManyField`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33151>
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/058.61bcba0b5aac5dbfd86e7812d25e59c6%40djangoproject.com.

Reply via email to