#25278: call_command should allow the first param to be a module
--------------------------------------------+--------------------
     Reporter:  mlissner                    |      Owner:  nobody
         Type:  New feature                 |     Status:  new
    Component:  Core (Management commands)  |    Version:  master
     Severity:  Normal                      |   Keywords:
 Triage Stage:  Unreviewed                  |  Has patch:  0
Easy pickings:  1                           |      UI/UX:  0
--------------------------------------------+--------------------
 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
 tests.py, I have a line of code like:

     call_command('my_custom_command')

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

     from my_app.management.commands import my_custom_command
     call_command(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')

 or

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

 With the emphasis being on the latter.

--
Ticket URL: <https://code.djangoproject.com/ticket/25278>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.04681d913c837885e9c5461afe793e1a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to