Opened 4 days ago

Last modified 4 days ago

#36010 assigned Bug

compilemessages reports errors only once

Reported by: Balazs Endresz Owned by: amansharma612
Component: Internationalization Version: dev
Severity: Normal Keywords:
Cc: Balazs Endresz Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When calling compilemessages for a locale that has invalid entries it prints out the errors correctly first.
But any subsequent calls just say that it's already compiled and up to date.
This is because msgfmt updates the last modified date of the mo file even if it's invalid, and then django will skip that locale afterwards:
https://github.com/django/django/blob/main/django/core/management/commands/compilemessages.py#L153

This can reproduced by calling compilemessages twice in django/tests/i18n/test_compilation.py:

class CompilationErrorHandling(MessageCompilationTests):
    def test_error_reported_by_msgfmt(self):
        # po file contains wrong po formatting.
        with self.assertRaises(CommandError):
            call_command("compilemessages", locale=["ja"], verbosity=0)

        # subsequent calls should still fail
        with self.assertRaises(CommandError):
            call_command("compilemessages", locale=["ja"], verbosity=0)  # currently this doesn't raise CommandError

One way of fixing this is perhaps doing the validation separately first, e.g. with mo_path = "NUL" if os.name == "nt" else "/dev/null" and then calling msgfmt again with the actual mo_path only if that passes.

Change History (2)

comment:1 by Claude Paroz, 4 days ago

Triage Stage: UnreviewedAccepted
Version: 5.1dev

Good catch! I think your suggested resolution strategy makes sense.

comment:2 by amansharma612, 4 days ago

Owner: set to amansharma612
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top