Opened 7 years ago

Closed 7 years ago

#24068 closed Bug (wontfix)

management commands' OutputWrapper adds newline wrapped inside style

Reported by: Markus Holtermann Owned by: Markus Holtermann
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Markus Holtermann)

According to the docs the self.stdout.write() adds a newline (or explicitly defined ending) add the end of the message, if it's not already there. However, if the output is wrapped in some kind of style the message, including the ending, is wrapped.

Instead of

'\x1b[31;1mHello, world!\x1b[0m\n'

one gets

'\x1b[31;1mHello, world!\n\x1b[0m'

The issue came up while investigating https://github.com/django/django/pull/3153#issuecomment-68471839

A potential patch would be:

  • django/core/management/base.py

    diff --git a/django/core/management/base.py b/django/core/management/base.py
    index 869a11b..318740f 100644
    a b class OutputWrapper(object): 
    107107        return getattr(self._out, name)
    108108
    109109    def write(self, msg, style_func=None, ending=None):
    110         ending = self.ending if ending is None else ending
    111         if ending and not msg.endswith(ending):
    112             msg += ending
    113110        style_func = style_func or self.style_func
    114         self._out.write(force_str(style_func(msg)))
     111        ending = self.ending if ending is None else ending
     112        if ending and msg.endswith(ending):
     113            msg = msg[:-len(ending)]
     114        msg = force_str(style_func(msg)) + ending
     115        self._out.write(msg)

Change History (3)

comment:1 Changed 7 years ago by Markus Holtermann

Description: modified (diff)
Needs tests: set
Owner: changed from nobody to Markus Holtermann
Status: newassigned

comment:2 Changed 7 years ago by Markus Holtermann

Description: modified (diff)

comment:3 Changed 7 years ago by Tim Graham

Resolution: wontfix
Status: assignedclosed

Let's focus our efforts on #21429 instead. We can merge PR 3823 to fix the particular problem.

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