Opened 17 months ago

Closed 17 months ago

Last modified 16 months ago

#22301 closed Bug (duplicate)

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

Reported by: tomasz.pazurkiewicz@… Owned by: claudep
Component: Core (Management commands) Version: master
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 Changed 17 months ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.6 to master

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 Changed 17 months ago by claudep

  • Owner changed from nobody to claudep
  • Status changed from new to assigned

comment:3 follow-up: Changed 17 months ago by claudep

  • Resolution set to duplicate
  • Status changed from assigned to closed

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

comment:4 in reply to: ↑ 3 Changed 16 months ago by tomasz.pazurkiewicz@…

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 Changed 16 months ago by claudep

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