Fixed #31428 -- Allowed empty message in management command self.stdout/err proxies.

This commit is contained in:
François Freitag 2020-04-06 12:12:41 +02:00 committed by Mariusz Felisiak
parent 5fbc0e07a9
commit e03eb8db93
5 changed files with 5 additions and 4 deletions

View File

@ -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'" %

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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()