Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33151 closed Bug (fixed)

createsuperuser doesn't work in non-interactive mode if a ManyToManyField is in REQUIRED_FIELDS.

Reported by: Christophe Henry Owned by: Christophe Henry
Component: contrib.auth Version: 3.1
Severity: Normal Keywords:
Cc: Hasan Ramezani Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#21755 added ForeignKey support to REQUIRED_FIELDS in createsuperuser command but this support is not working in non-interactive mode.

The buggy line is this line. If value is an integer, field.clean() simply returns it after validation while `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 `ForeignKey.to_python()` expects an integer.

There may be the same problem with ManyToManyField.

Attachments (2)

django.patch (1.8 KB ) - added by Christophe Henry 3 years ago.
Proposed patch to fix the bug
33151.diff (1.8 KB ) - added by Christophe Henry 3 years ago.
Proposed patch to fix the bug

Download all attachments as: .zip

Change History (14)

by Christophe Henry, 3 years ago

Attachment: django.patch added

Proposed patch to fix the bug

comment:1 by Christophe Henry, 3 years ago

I just posted a patch proposing a fix for this bug. I'm open to comments on this solutions and suggestions on how to fix the ManyToManyField case.

by Christophe Henry, 3 years ago

Attachment: 33151.diff added

Proposed patch to fix the bug

comment:2 by Christophe Henry, 3 years ago

Has patch: set
Needs tests: set
Patch needs improvement: set

comment:3 by Christophe Henry, 3 years ago

Owner: changed from nobody to Christophe Henry
Status: newassigned

comment:4 by Mariusz Felisiak, 3 years ago

Cc: Hasan Ramezani added
Summary: Super user creation always raises an error in non-interactive mode when on required field is a ForeignKeycreatesuperuser doesn't work in non-interactive mode if a ManyToManyField/ForeignKey is in REQUIRED_FIELDS.
Triage Stage: UnreviewedAccepted

comment:5 by Christophe Henry, 3 years ago

Has patch: unset
Needs tests: unset
Patch needs improvement: unset

comment:6 by Christophe Henry, 3 years ago

#14913 is fixing this one and is ready for review.

comment:7 by Jacob Walls, 3 years ago

Has patch: set

comment:8 by Mariusz Felisiak, 3 years ago

Patch needs improvement: set

comment:9 by Mariusz Felisiak, 3 years ago

Summary: createsuperuser doesn't work in non-interactive mode if a ManyToManyField/ForeignKey is in REQUIRED_FIELDS.createsuperuser doesn't work in non-interactive mode if a ManyToManyField is in REQUIRED_FIELDS.

comment:10 by Mariusz Felisiak, 3 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In df2d2bc9:

Fixed #33151 -- Fixed createsuperuser crash for many-to-many required fields in non-interactive mode.

comment:12 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In f2a5963:

[4.0.x] Fixed #33151 -- Fixed createsuperuser crash for many-to-many required fields in non-interactive mode.

Backport of df2d2bc95c451c6366fd522a5a1e6ed84f459f31 from main

Note: See TracTickets for help on using tickets.
Back to Top