Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#27769 closed Bug (fixed)

createsuperuser command missing docs about no-input/interactive

Reported by: Kenny Loveall Owned by: Andrew Nester
Component: Documentation Version: dev
Severity: Normal Keywords: createsuperuser
Cc: 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

From what I can tell, it is impossible to call the createsuperuser command using the call_command function.

If this is intentional, it should be documented on one of the two functions.

Steps to Reproduce:
run "call_command('createsuperuser', noinput=True, username='test', email='test@…')" from a non-interactive command (such as calling it inside a view).

Expected outcome:
Superuser is created without a password.

Observed outcome:
500 error and message "Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser in your project to create one manually." logged.

From what I can tell as well, there's no way to run createsuperuser and have it create a user without a password as the documentation states is possible ("When run non-interactively, no password will be set").

Change History (9)

comment:1 by Claude Paroz, 7 years ago

Component: Core (Management commands)Documentation
Summary: Impossible to call createsuperuser from call_commandcreatesuperuser command missing docs about no-input/interactive
Triage Stage: UnreviewedAccepted
Version: 1.8master

The issue stems from the fact that the --no-input command line flag is translating to the interactive variable which should be used when calling the command through call_command.
call_command('createsuperuser', interactive=False, username='test', email=​'test@example.com') should then work.

The documentation should really be improved in this case (https://docs.djangoproject.com/en/stable/ref/django-admin/#createsuperuser).

comment:2 by Andrew Nester, 7 years ago

Has patch: set
Owner: changed from nobody to Andrew Nester
Status: newassigned

I've added PR for this #PR

comment:3 by Tim Graham, 7 years ago

Patch needs improvement: set

I think it's more appropriate to highlight this in the call_command() documentation as it applies to any command that takes the --no-input argument. More generally, we should instruct users how to figure out the name to pass for any option. I'm not sure if there's a way besides looking up dest='...' in the source code.

comment:4 by Andrew Nester, 7 years ago

Patch needs improvement: unset

I've updated my PR according to comments.

comment:5 by Kenny Loveall, 7 years ago

Wonderful! That does work. I would think it should be highlighted both places.

Personally I could never figure out how to make createsuperuser run in a non-interactive fashion (I assumed the --no-input flag did that). Nowhere on the documentation page for manage.py commands does it mention the --interactive=False flag (--no-input, however is mentioned on many of the commands which is why I assumed it was the way to make this work).

comment:6 by Claude Paroz, 7 years ago

The flag names when calling from command line do not always match the kwarg names that call_command must use (depends on the dest name in the command option definitions).

comment:7 by Tim Graham, 7 years ago

Triage Stage: AcceptedReady for checkin

Besides the documentation enhancement, #27787 will improve the situation so that call_command() rejects unexpected options.

comment:8 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In c8d21f33:

Fixed #27769 -- Documented option naming differences between django-admin and call_command().

comment:9 by Tim Graham <timograham@…>, 7 years ago

In 33ff4e4e:

[1.11.x] Fixed #27769 -- Documented option naming differences between django-admin and call_command().

Backport of c8d21f335113dcf6009d7aa9810d4e77dc58c75d from master

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