Opened 8 years ago

Last modified 8 years ago

#24068 closed Bug

management commands' OutputWrapper adds newline wrapped inside style — at Initial Version

Reported by: Markus Holtermann Owned by: nobody
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

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..e29bb8a 100644
    a b class OutputWrapper(object): 
    107107        return getattr(self._out, name)
    108108
    109109    def write(self, msg, style_func=None, ending=None):
     110        style_func = style_func or self.style_func
    110111        ending = self.ending if ending is None else ending
     112        msg = force_str(style_func(msg))
    111113        if ending and not msg.endswith(ending):
    112114            msg += ending
    113         style_func = style_func or self.style_func
    114         self._out.write(force_str(style_func(msg)))
     115        self._out.write(msg)
    115116
    116117
    117118class BaseCommand(object):

Change History (0)

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