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

Fix lazy translation of ListField errors #6708

Merged
merged 2 commits into from
May 23, 2019

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented May 23, 2019

Spun this off of #6644.

  • Fixes lazy translations for ListField.
  • Adds a regression test to ensure that fields with lazily translated validation errors can be imported and instantiated during class creation. This test fails without the corresponding fix to ListField.
  • Clarifies purposes of tests.importable
Test failure snippet:
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/tests/importable/__init__.py", line 10, in <module>
INTERNALERROR>     class ExampleSerializer(serializers.Serializer):
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/tests/importable/__init__.py", line 16, in ExampleSerializer
INTERNALERROR>     listfield = serializers.ListField(min_length=1, max_length=2)
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/rest_framework/fields.py", line 1613, in __init__
INTERNALERROR>     message = self.error_messages['max_length'].format(max_length=self.max_length)
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/.tox/venvs/py37-django22/lib/python3.7/site-packages/django/utils/functional.py", line 151, in __wrapper__
INTERNALERROR>     res = func(*self.__args, **self.__kw)
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/.tox/venvs/py37-django22/lib/python3.7/site-packages/django/utils/translation/__init__.py", line 79, in gettext
INTERNALERROR>     return _trans.gettext(message)
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/.tox/venvs/py37-django22/lib/python3.7/site-packages/django/utils/translation/trans_real.py", line 285, in gettext
INTERNALERROR>     _default = _default or translation(settings.LANGUAGE_CODE)
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/.tox/venvs/py37-django22/lib/python3.7/site-packages/django/utils/translation/trans_real.py", line 198, in translation
INTERNALERROR>     _translations[language] = DjangoTranslation(language)
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/.tox/venvs/py37-django22/lib/python3.7/site-packages/django/utils/translation/trans_real.py", line 97, in __init__
INTERNALERROR>     self._add_installed_apps_translations()
INTERNALERROR>   File "/Users/bagel/Documents/projects/django-rest-framework/.tox/venvs/py37-django22/lib/python3.7/site-packages/django/utils/translation/trans_real.py", line 139, in _add_installed_apps_translations
INTERNALERROR>     "The translation infrastructure cannot be initialized before the "
INTERNALERROR> django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

@rpkilby rpkilby added this to the 3.10 Release milestone May 23, 2019
@rpkilby rpkilby changed the title Test init for fields w/ lazy translations Fix lazy translation of ListField errors May 23, 2019
@rpkilby
Copy link
Member Author

rpkilby commented May 23, 2019

Going ahead and merging - I don't think any of this is controversial.

@rpkilby rpkilby merged commit 19ca86d into encode:master May 23, 2019
@rpkilby rpkilby deleted the fix-lazy-translations branch May 23, 2019 02:41
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
* Test init for fields w/ lazy translations
* Fix lazy translations for ListField
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
* Test init for fields w/ lazy translations
* Fix lazy translations for ListField
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant