Skip to content

Commit

Permalink
Fixed #32094 -- Fixed flush() calls on management command self.stdout…
Browse files Browse the repository at this point in the history
…/err proxies.
  • Loading branch information
thomas-riccardi authored and felixxm committed Oct 9, 2020
1 parent b7da588 commit f1f2453
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django/core/management/base.py
Expand Up @@ -140,6 +140,10 @@ def __init__(self, out, ending='\n'):
def __getattr__(self, name):
return getattr(self._out, name)

def flush(self):
if hasattr(self._out, 'flush'):
self._out.flush()

def isatty(self):
return hasattr(self._out, 'isatty') and self._out.isatty()

Expand Down
8 changes: 8 additions & 0 deletions tests/user_commands/management/commands/outputwrapper.py
@@ -0,0 +1,8 @@
from django.core.management.base import BaseCommand


class Command(BaseCommand):
def handle(self, **options):
self.stdout.write('Working...')
self.stdout.flush()
self.stdout.write('OK')
7 changes: 7 additions & 0 deletions tests/user_commands/tests.py
Expand Up @@ -341,6 +341,13 @@ def test_create_parser_kwargs(self):
parser = BaseCommand().create_parser('prog_name', 'subcommand', epilog=epilog)
self.assertEqual(parser.epilog, epilog)

def test_outputwrapper_flush(self):
out = StringIO()
with mock.patch.object(out, 'flush') as mocked_flush:
management.call_command('outputwrapper', stdout=out)
self.assertIn('Working...', out.getvalue())
self.assertIs(mocked_flush.called, True)


class CommandRunTests(AdminScriptTestCase):
"""
Expand Down

0 comments on commit f1f2453

Please sign in to comment.