Opened 9 years ago

Closed 9 years ago

Last modified 4 months ago

#26940 closed Bug (fixed)

makemessages incorrectly configured as not requiring settings

Reported by: Jorge Romero Owned by: nobody
Component: Internationalization Version: dev
Severity: Normal Keywords: translations
Cc: Claude Paroz Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django-admin and manage.py are supposed to be interchangeable.

From the docs(https://docs.djangoproject.com/en/1.9/ref/django-admin/):

The command-line examples throughout this document use django-admin to be consistent, but any example can use manage.py or python -m django just as well.

However, this doesn't seem to be true for makemessages.

If I run manage.py makemessages from the top level of the project MEDIA_ROOT and STATIC_ROOT are ignored. This isn't precisely a bug because that's what the code is intended to do (https://github.com/django/django/blob/master/django/core/management/commands/makemessages.py#L448), but I find it strange specially for --domain djangojs because is very common for Javascript files to be put in STATIC_ROOT.

django-admin makemessages doesn't ignore MEDIA_ROOT or STATIC_ROOT and it traverses the entire source tree.

At least this should be explained in the documentation. At best both commands should do the exact same. It's very easy to be bitten by this as we don't always review the resulting *.po file.

Am I missing something here?

Change History (12)

comment:1 by Simon Charette, 9 years ago

Maybe the documentation should mention that --settings must be specified to django-admin and python -m django for them to be interchangeable with manage.py.

comment:2 by Claude Paroz, 9 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Currently, makemessages is explicitly whitelisted as not needing a configured settings file (see no_settings_commands in django.core.management.__init__.py.
I wonder now if we should revert that, considering the dependency of that command on settings.FILE_CHARSET, settings.LOCALE_PATHS, settings.MEDIA_ROOT, and settings.STATIC_ROOT.

comment:3 by Claude Paroz, 9 years ago

Has patch: set
Version: 1.9master

comment:4 by Tim Graham, 9 years ago

Summary: django-admin makemessages vs. manage.py makemessagesmakemessages incorrectly configured as not requiring settings
Triage Stage: AcceptedReady for checkin

comment:5 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In a6baada7:

Fixed #26940 -- Removed makemessages from no_settings_commands whitelist

As makemessages uses several settings for proper run (FILE_CHARSET,
LOCALE_PATHS, MEDIA_ROOT, and STATIC_ROOT), we should require settings
configuration for this command.

comment:6 by Claude Paroz, 9 years ago

Resolution: fixed
Status: closednew
Triage Stage: Ready for checkinUnreviewed

I'm considering reverting the fact that we require configured settings for makemessages.
I'm thinking about the use case of reusable apps, when you typically don't have/need STATIC_ROOT/MEDIA_ROOT/LOCALE_PATHS, and most of the time FILE_CHARSET in utf-8 is fine.
See this commit, above that PR.

comment:7 by Claude Paroz, 9 years ago

Here's the PR.

comment:8 by Tim Graham, 9 years ago

Triage Stage: UnreviewedReady for checkin

comment:9 by Claude Paroz <claude@…>, 9 years ago

In fa2f55c:

Refs #26940 -- Re-allowed makemessages without settings

Thanks Tim Graham for the review.

comment:10 by Claude Paroz, 9 years ago

Resolution: fixed
Status: newclosed

comment:11 by Natalia Bidart, 4 months ago

Cc: Claude Paroz added

There seems to be a potential regression about this in current main (6.0 development cycle). When running:

$ django-admin --version
6.0.dev20250506141140
$ django-admin makemessages --all -v 2
Traceback (most recent call last):
  File "/home/nessita/.venvs/djangodev-3.13/bin/django-admin", line 8, in <module>
    sys.exit(execute_from_command_line())
             ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/nessita/fellowship/django/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
    ~~~~~~~~~~~~~~~^^
  File "/home/nessita/fellowship/django/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/nessita/fellowship/django/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nessita/fellowship/django/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/home/nessita/fellowship/django/django/core/management/commands/makemessages.py", line 372, in handle
    % get_text_list(list(self.extensions), "and")
      ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nessita/fellowship/django/django/utils/functional.py", line 231, in wrapper
    return func(*args, **kwargs)
  File "/home/nessita/fellowship/django/django/utils/text.py", line 306, in get_text_list
    _(", ").join(str(i) for i in list_[:-1]),
    ~^^^^^^
  File "/home/nessita/fellowship/django/django/utils/translation/__init__.py", line 96, in gettext
    return _trans.gettext(message)
           ^^^^^^^^^^^^^^
  File "/home/nessita/fellowship/django/django/utils/translation/__init__.py", line 66, in __getattr__
    if settings.USE_I18N:
       ^^^^^^^^^^^^^^^^^
  File "/home/nessita/fellowship/django/django/conf/__init__.py", line 75, in __getattr__
    self._setup(name)
    ~~~~~~~~~~~^^^^^^
  File "/home/nessita/fellowship/django/django/conf/__init__.py", line 55, in _setup
    raise ImproperlyConfigured(
    ...<4 lines>...
    )
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

comment:12 by Claude Paroz, 4 months ago

Thanks for noticing, we should probably deactivate translations around the call to get_text_list.

Note: See TracTickets for help on using tickets.
Back to Top