From e03eb8db9371c2af864b124701b8f970ff405ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Mon, 6 Apr 2020 12:12:41 +0200 Subject: [PATCH] Fixed #31428 -- Allowed empty message in management command self.stdout/err proxies. --- django/contrib/staticfiles/management/commands/collectstatic.py | 2 +- django/core/management/base.py | 2 +- django/core/management/commands/loaddata.py | 2 +- tests/user_commands/management/commands/hal.py | 1 + tests/user_commands/tests.py | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index b2995acc7e..ce2691aff2 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -129,7 +129,7 @@ class Command(BaseCommand): self.stderr.write("Post-processing '%s' failed!" % original_path) # Add a blank line before the traceback, otherwise it's # too easy to miss the relevant part of the error message. - self.stderr.write("") + self.stderr.write() raise processed if processed: self.log("Post-processed '%s' as '%s'" % diff --git a/django/core/management/base.py b/django/core/management/base.py index f92ceb17d8..74ffc94dcf 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -137,7 +137,7 @@ class OutputWrapper(TextIOBase): def isatty(self): return hasattr(self._out, 'isatty') and self._out.isatty() - def write(self, msg, style_func=None, ending=None): + def write(self, msg='', style_func=None, ending=None): ending = self.ending if ending is None else ending if ending and not msg.endswith(ending): msg += ending diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index fb7cf303f2..bdc0c03178 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -196,7 +196,7 @@ class Command(BaseCommand): if obj.deferred_fields: self.objs_with_deferred_fields.append(obj) if objects and show_progress: - self.stdout.write('') # add a newline after progress indicator + self.stdout.write() # Add a newline after progress indicator. self.loaded_object_count += loaded_objects_in_fixture self.fixture_object_count += objects_in_fixture except Exception as e: diff --git a/tests/user_commands/management/commands/hal.py b/tests/user_commands/management/commands/hal.py index 120eec961f..5791e5fae0 100644 --- a/tests/user_commands/management/commands/hal.py +++ b/tests/user_commands/management/commands/hal.py @@ -12,6 +12,7 @@ class Command(BaseCommand): app_labels = set(app_labels) if options['empty']: + self.stdout.write() self.stdout.write("Dave, I can't do that.") return diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index 4e730472f5..b770e8e459 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -124,7 +124,7 @@ class CommandTests(SimpleTestCase): def test_calling_a_command_with_only_empty_parameter_should_ends_gracefully(self): out = StringIO() management.call_command('hal', "--empty", stdout=out) - self.assertIn("Dave, I can't do that.\n", out.getvalue()) + self.assertEqual(out.getvalue(), "\nDave, I can't do that.\n") def test_calling_command_with_app_labels_and_parameters_should_be_ok(self): out = StringIO()