Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#10814 closed (wontfix)

management loaddata with verbosity > 0 fails silently under WSGI

Reported by: Charlie DeTar Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: management loaddata verbosity stdout wsgi
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When using mod_wsgi and apache, a script which calls the following fails silently:

    from django.core import management
    management.call_command("loaddata", "some_fixture")

Presumably, this has something to do with the fact that by default, "loaddata" prints status information to standard out, which is forbidden under WSGI. The same command with "verbosity=0" succeeds.

Rather than failing silently, the call with verbosty > 0 should either function properly or raise an exception when run under WSGI.

Change History (6)

comment:1 Changed 15 years ago by Graham Dumpleton

The command should be changed to redirect stdout to stderr if you cannot actually change loaddata to print debug messages to stderr.

Ultimately in mod_wsgi 3.0 I have given up trying to encourage people to write portable WSGI application code.


comment:2 Changed 15 years ago by James Bennett

Triage Stage: UnreviewedDesign decision needed

Personally I'm inclined toward wontfix on this one, for a few reasons:

  1. Management commands are typically designed to be invoked via the command line or, in some cases, as cron jobs. While you can invoke them from web requests, that's not really the use case they primarily target.
  1. Even if we were to decide to work around this in some fashion, we'd be left with a glaring problem: there's no way to tell (AFAIK), from inside the management command, that it's been invoked during processing of a request through WSGI.
  1. It's easy enough to just dial down the verbosity as your situation warrants.

comment:3 Changed 15 years ago by James Bennett

(and perhaps the proper solution here would really be to add documentation on calling commands in this fashion, warning people to set verbosity to 0 or redirect stdout)

comment:4 Changed 15 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

I concur with James. The management commands write to stdout, pretty much by definition. WSGI, again pretty much by definition, doesn't like scripts to write to stdout. This is one of those "Doctor, it hurts when I do X"; "Then don't do X" situations.

@grahamd - Errors are already written to stderr; writing notifications and other progress output to stderr isn't appropriate behavior for the normal use case - calling the management command from the command line. verbosity=0 exists for situations where you don't want terminal output from management commands.

comment:5 Changed 15 years ago by Graham Dumpleton

Does the call_command() function allow the equivalent of:

loaddata some_fixture 1>&2

This is what I meant when command should be changed to redirect stdout to stderr.

comment:6 Changed 15 years ago by Russell Keith-Magee

@grahamd - call_command() doesn't provide an analog of 1>&2 redirection, but if that's what the user wants to do, they can do that by manipulating sys.stdout et al.

This isn't a use case that we particularly want to encourage (as James noted - the management commands are really for management, not web requests), and given that it can be handled by the end user, I'm not convinced it's a necessary feature addition for the core.

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