#2062: [PATCH] subtle gettext issue when tg is partially loaded
------------------------+---------------------------------------------------
Reporter: cdevienne | Owner: faide
Type: defect | Status: new
Priority: normal | Milestone: 1.0.x bugfix
Component: TurboGears | Version: 1.0.7
Severity: normal | Keywords:
------------------------+---------------------------------------------------
Since I had fun tracking this one down, I thought I would share this joy :
The issue arose when I was documenting my application with Sphinx using
autodoc.
* At one moment, my controller modules get loaded, but at this moment,
for some reasons, i18n.install() has _not_ been called yet.
* In one of the module I have a ToscaWidgets form, with input widgets in
it, which is instantiated as a global variable.
* When the form is instantiated, the children widgets gets copied.
* When the input widgets get copied, its attributes get copied
* One of the attributes is a property called "is_required", which tries
to validate an empty string with the widget validator.
* Because one of my fields is indeed required, the validator wants to
raise the Invalid exception, and start by formatting its message.
* The message formatting consist in the first place to translate the
message template using the builtin gettext, ie `__builtin__._`.
Reminding that i18n.install was not yet called ?
{{{
File "/home/cdevienne/prog/tw.forms/tw/forms/core.py", line 56, in
__new__
obj = super(InputWidget, cls).__new__(cls, id, parent, children, **kw)
File "/home/cdevienne/ws/starform/sf_env/lib/python2.5/site-
packages/ToscaWidgets-0.9.3-py2.5.egg/tw/core/base.py", line 288, in
__new__
attr = getattr(obj, name, None)
File "/home/cdevienne/prog/tw.forms/tw/forms/fields.py", line 104, in
is_required
self.validate('', use_request_local=False)
File "/home/cdevienne/prog/tw.forms/tw/forms/core.py", line 130, in
validate
value = self.validator.to_python(value, state)
File "/home/cdevienne/ws/starform/sf_env/lib/python2.5/site-
packages/FormEncode-1.2-py2.5.egg/formencode/api.py", line 395, in
to_python
raise Invalid(self.message('empty', state), value, state)
File "/home/cdevienne/ws/starform/sf_env/lib/python2.5/site-
packages/FormEncode-1.2-py2.5.egg/formencode/api.py", line 229, in message
return trans(self._messages[msgName], **self.gettextargs) % kw
TypeError: ugettext() got an unexpected keyword argument 'domain'
}}}
And indeed, Validator.gettextargs contains a "domain" key, which is set to
"FormEncode". Who did that ? turbogears.validators.
==== Explanation ====
In the end the problem is that Validator.gettextargs setting made by
turbogears.validators assumes that `__builtin__._` is indeed
`turbogears.i18n.gettext`. But it may not be true in some conditions.
==== Workaround ====
Put Validator.gettextargs = {} just after loading turbogears.validators
==== Solution ====
Put `Validator.gettextargs['domain'] = 'FormEncode'` in i18n.install().
Patch attached.
--
Ticket URL: <http://trac.turbogears.org/ticket/2062>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---