Opened 9 years ago

Closed 9 years ago

#25278 closed New feature (wontfix)

call_command should allow the first param to be a module

Reported by: Mike Lissner Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The current API for the call_command function is:

call_command(name, *args, options)

Where name is a string, args is a list, and options is a dict. So in my, I have a line of code like:


This works pretty well, but it limits my ability to rename the command. If instead I were able to write:

from import my_custom_command

That would mean that my IDE could automatically update this code if I ever renamed the file. (Most IDEs I'm familiar with can do refactoring of module and file names, but fall down if those names are in strings or comments.)

In call_command, a simple test could be made to convert the module to a string if needed, and then run as it does presently. To me, this makes sense as the recommended API for call_command.

If others agree, I think we should treat this in the documentation the same way as we do the initialization of ForeignKey, where you can either write:

my_key = models.ForeignKey('Book')


from my_app.models import Book
my_key = models.ForeignKey(Book)

With the emphasis being on the latter.

Change History (1)

comment:1 by Tim Graham, 9 years ago

Easy pickings: unset
Resolution: wontfix
Status: newclosed

I don't think the IDE renaming advantages provide sufficient justification for the additional complexity that would be required, but feel free to raise the idea on the DevelopersMailingList to get more feedback. The reason ForeignKey also accepts a string is to avoid circular references.

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