Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New project fails with USE_I18N=False #6539

Closed
gasman opened this issue Nov 11, 2020 · 0 comments · Fixed by #6547
Closed

New project fails with USE_I18N=False #6539

gasman opened this issue Nov 11, 2020 · 0 comments · Fixed by #6547
Labels
component:i18n i18n for content created in Wagtail, not the admin UI itself type:Bug
Milestone

Comments

@gasman
Copy link
Collaborator

gasman commented Nov 11, 2020

Issue Summary

Initial migrations fail on Wagtail 2.11.1 with USE_I18N = False and LANGUAGE_CODE = 'en-us' in settings.

Steps to Reproduce

  1. Start a new project with wagtail start myproject
  2. Edit myproject/settings/base.py and set USE_I18N = False
  3. Run ./manage.py migrate

This throws the exception:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 92, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/db/migrations/loader.py", line 53, in __init__
    self.build_graph()
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/db/migrations/loader.py", line 210, in build_graph
    self.load_disk()
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/django/db/migrations/loader.py", line 112, in load_disk
    migration_module = import_module(migration_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/wagtail/core/migrations/0056_page_locale_fields_populate.py", line 8, in <module>
    class Migration(migrations.Migration):
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/wagtail/core/migrations/0056_page_locale_fields_populate.py", line 15, in Migration
    BootstrapTranslatableModel('wagtailcore.Page'),
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/wagtail/core/models.py", line 538, in __init__
    language_code = get_supported_content_language_variant(settings.LANGUAGE_CODE)
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/wagtail/core/utils.py", line 261, in get_supported_content_language_variant
    supported_lang_codes = get_content_languages()
  File "/Users/matthew/.virtualenvs/use18n/lib/python3.7/site-packages/wagtail/core/utils.py", line 224, in get_content_languages
    (default_language_code, languages[default_language_code]),
KeyError: 'en-us'

This seems to happen because with USE_I18N = False, the implementation of get_supported_language_variant in Django's 'null' i18n backend returns LANGUAGE_CODE unchanged, whereas the real one takes fallbacks into account (returning 'en' for 'en-us'). Wagtail's get_content_languages then expects to find this in settings.LANGUAGES, which fails because Django's master LANGUAGES list contains 'en', not 'en-us'.

  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes

Technical details

  • Python version: 3.7.2
  • Django version: 3.1.3
  • Wagtail version: 2.11.1
@gasman gasman added type:Bug component:i18n i18n for content created in Wagtail, not the admin UI itself labels Nov 11, 2020
@gasman gasman added this to the 2.11.2 milestone Nov 11, 2020
gasman added a commit to gasman/wagtail that referenced this issue Nov 13, 2020
gasman added a commit to gasman/wagtail that referenced this issue Nov 16, 2020
gasman added a commit that referenced this issue Nov 16, 2020
…t in LANGUAGES (#6547)

* Handle get_supported_language_variant returning a language variant not in LANGUAGES

Fixes #6539

* Handle LANGUAGE_CODE that isn't in LANGUAGES

* Release note for #6547
gasman added a commit that referenced this issue Nov 16, 2020
…t in LANGUAGES (#6547)

* Handle get_supported_language_variant returning a language variant not in LANGUAGES

Fixes #6539

* Handle LANGUAGE_CODE that isn't in LANGUAGES

* Release note for #6547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:i18n i18n for content created in Wagtail, not the admin UI itself type:Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant