#36368: `makemessages` command runs `write_po_file()` multiple times for the
same
potfile
-------------------------------------+-------------------------------------
Reporter: MichaĆ Pokusa | Type: Bug
Status: new | Component: Core
| (Management commands)
Version: 5.2 | Severity: Normal
Keywords: makemessages | Triage Stage:
write_po_file | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
This is both a Bug and a Cleanup/optimization issue.
In some cases, the `makemessages` management command will run
`write_po_file()` multiple times per the same potfile and locale.
1. It happens because inside `handle()`, the `write_po_file()` method is
called in a for loop for every `potfile`:
https://github.com/django/django/blob/main/django/core/management/commands/makemessages.py#L459
2. `potfiles` is a `list`, and that makes it possible for it to have
duplicates, which is exactly the case when the bug described here happens.
Inside `build_potfiles()`, used for `potfiles` inside `handle()`, inside a
for loop for every path in `self.locale_paths`, the returned list is
appended.
https://github.com/django/django/blob/main/django/core/management/commands/makemessages.py#L513
3. The `self.locale_paths` is also a list, and it also can have
duplicates, because e.g. when the `<project root>/locale` folder is
present, it is being appended twice:
https://github.com/django/django/blob/main/django/core/management/commands/makemessages.py#L384
4. Later, it is possible that inside the `find_files()`, the same locale
path is inserted to `self.locale_paths` once again, which makes it
possible to have 2 duplicates or 3 in total of the same locale path.
I propose the solution to change `self.locale_paths` from `list` to `set`,
and do the same for `potfiles` inside `handle()`, after doing that the
problems seems to be fixed. This also shouldn't break anything, because it
looks like this is how it is supposed to work, meaning ony one occurence
of each value.
If the issue is accepted I would be happy to be assigned to it and make a
PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/36368>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070196a1e90487-eb93f981-a736-44d8-b86b-4b88d6d6e571-000000%40eu-central-1.amazonses.com.