#22301 closed Bug (duplicate)
Management command style should check self.output.isatty()
| Reported by: | 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 , 12 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | 1.6 → master |
comment:2 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
follow-up: 4 comment:3 by , 12 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | assigned → 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 by , 12 years ago
Replying to claudep:
In that case, the output coloring is not done by
OutputWrapper, but by thesqlfamily of commands. A new--no-coloroption 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 , 12 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.
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.writealso takes astyle_funcparameter 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