Opened 7 years ago

Closed 7 years ago

#7316 closed (fixed)

Use ugettext_lazy instead of ugettext in contrib.localflavor

Reported by: msaelices Owned by: msaelices
Component: contrib.localflavor Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


There are many files in localflavor that uses ugettext for defining fields and widgets, for example:

from django.utils.translation import ugettext

class NOSocialSecurityNumber(Field):
    Algorithm is documented at
    default_error_messages = {
        'invalid': ugettext(u'Enter a valid Norwegian social security number.'),

This can produce a serious problem (in production server), because two things:

  1. String translation is got in import time, for example when web server starts. This string will never change.
  2. This is the most important problem: You could have error with circulars import, because gettext call will try import all applications installed on Django, but this file haven't loaded yet. I had this problem with Apache for a import cycle, because a contrib.localflavor import. This is not acceptable.

I will attach a patch for fix this problem.

Attachments (1)

localflavor_r7554.diff (20.9 KB) - added by msaelices 7 years ago.
Patch that fixes problem.

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by msaelices

Patch that fixes problem.

comment:1 Changed 7 years ago by Simon Greenhill

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [7689]) Fixed #7554 -- Modified contrib.localflavor to make use of ugettext, rather than ugettext. Thanks to msaelices for the report and patch.

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