Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22301 closed Bug (duplicate)

Management command style should check self.output.isatty()

Reported by: tomasz.pazurkiewicz@… Owned by: Claude Paroz
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When running output = io.StringIO(); django.core.management.call_command('sql', 'myapp', output=output)
management command ignores that self.output is not a tty and writes colored output. However, color settings set in init check if sys.stdout is a tty.

Change History (5)

comment:1 by Baptiste Mispelon, 10 years ago

Triage Stage: UnreviewedAccepted
Version: 1.6master

Hi,

It seems there is some code to try and not use style functions when not running in a TTY [1] but it's not enough.

From a quick look, it seems that OutputWrapper.write also takes a style_func parameter and it will use it even when not in a TTY which is probably the source of the problem.

[1] https://github.com/django/django/blob/master/django/core/management/base.py#L60

comment:2 by Claude Paroz, 10 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned

comment:3 by Claude Paroz, 10 years ago

Resolution: duplicate
Status: assignedclosed

In that case, the output coloring is not done by OutputWrapper, but by the sql family of commands. A new --no-color option has been added now (#19877) and will be available in Django 1.7.
https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-option---no-color

in reply to:  3 comment:4 by tomasz.pazurkiewicz@…, 10 years ago

Replying to claudep:

In that case, the output coloring is not done by OutputWrapper, but by the sql family of commands. A new --no-color option has been added now (#19877) and will be available in Django 1.7.

In my case using --no-color works.
But I think this issue shouldn't be closed - it's strange that the command produces different output depending on sys.stdout, which isn't even used.

comment:5 by Claude Paroz, 10 years ago

I closed it because the use case given in the description is already solved by #19877. If you can demonstrate a different valid use case which is problematic, then let's reopen the ticket.

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