#23098: ugettext_lazy gets translated too early in modelForm field choices
------------------------------+--------------------
     Reporter:  magopian      |      Owner:  nobody
         Type:  Bug           |     Status:  new
    Component:  Translations  |    Version:  master
     Severity:  Normal        |   Keywords:
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+--------------------
 This ticket first was submitted against the pytest_django repository:
 https://github.com/pelme/pytest_django/issues/135

 However, I think the maintainer is right and it's a Django bug: because of
 the new feature allowing to customize the "empty choice", the lazy
 translation of named groups in a choice list for a modelForm field gets
 translated at import time.

 The steps to reproduce are in the ticket linked above, and consists in:
 - have a choice list for a model field which contains name groups, with
 the groups' names being translated (using ugettext_lazy)
 - create a ModelForm for this model
 - import the ModelForm from an external script that has the settings
 configured, but not called `django.setup()` yet

 I understand the steps to reproduce are really a corner case and may seem
 irrelevant, but this bug means that we might have '''lazy translations
 that are translated way to early (at import time) instead of staying
 lazy'''.

 With the normal Django usage, this will translate too early silently, and
 not raise any error exception.

 From what I understand, this happens in the code that checks if the choice
 (in our case, the name of a group) is the empty choice:
 
https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L732

 I can imagine two solutions to this issue:
 1/ only do the check if the "choice" isn't a group name
 2/ do something like `choice is None or isinstance(choice, six.text_type)
 and choice == ''`

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23098>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.7a3dbe8cc26e1320b360c9d13f6a7f35%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to