Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10167 closed (worksforme)

RegexField: error_message is evaluated instead of tested for None

Reported by: dmach Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In RegexField, the error_message argument is evaluated instead of tested for None.

If USE_I18N is enabled and RegexField(error_message=_(...)) appears in any app's _ _init_ _.py, it leads to a traceback.

(project: myproj, application: myapp)
$ python manage.py syncdb

...
  File "/usr/lib/python2.4/site-packages/django/forms/fields.py", line 400, in __init__
    if error_message:
  File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 188, in __wrapper__
    res = self.__func(*self.__args, **self.__kw)
  File "/usr/lib/python2.4/site-packages/django/utils/translation/__init__.py", line 62, in ugettext
    return real_ugettext(message)
  File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 290, in ugettext
    return do_translate(message, 'ugettext')
  File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 280, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 198, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 181, in _fetch
    app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:])
AttributeError: 'module' object has no attribute 'myapp'

Attached patch solves the problem.

Attachments (1)

fields.diff (579 bytes) - added by dmach 5 years ago.

Download all attachments as: .zip

Change History (4)

Changed 5 years ago by dmach

comment:1 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by russellm

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

I cannot reproduce this problem - it looks like it may have been inadvertently fixed by the changes from [10088], when import_module was introduced.

If this is still posing problems for you, please reopen with a complete set of reproduction notes.

comment:3 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.