diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 09346b4d27..6374ed0d11 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -527,6 +527,11 @@ class Command(BaseCommand): ) ) continue + except BaseException: + # Cleanup before exit. + for build_file in build_files: + build_file.cleanup() + raise build_files.append(build_file) if self.domain == 'djangojs': diff --git a/tests/i18n/commands/templates/template_0_with_no_error.tpl b/tests/i18n/commands/templates/template_0_with_no_error.tpl new file mode 100644 index 0000000000..8abd38e603 --- /dev/null +++ b/tests/i18n/commands/templates/template_0_with_no_error.tpl @@ -0,0 +1,6 @@ +{% load i18n %} +{% blocktranslate %}Hello{% endblocktranslate %} + +This file has a name that should be lexicographically before +'template_with_error.tpl' so that we can test the cleanup case +of the first file being successful, but the second failing. diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index 3ba371f66c..124d35313f 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -226,8 +226,9 @@ class BasicExtractorTests(ExtractorTests): ) with self.assertRaisesMessage(SyntaxError, msg): management.call_command('makemessages', locale=[LOCALE], extensions=['tpl'], verbosity=0) - # The temporary file was cleaned up + # The temporary files were cleaned up. self.assertFalse(os.path.exists('./templates/template_with_error.tpl.py')) + self.assertFalse(os.path.exists('./templates/template_0_with_no_error.tpl.py')) def test_unicode_decode_error(self): shutil.copyfile('./not_utf8.sample', './not_utf8.txt')