[trunk] unsupported locale with Python 2.4

Bug #322432 reported by EdbO
12
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Undecided
Unassigned

Bug Description

Used same trunk version as in https://bugs.launchpad.net/bugs/322025 (where I said to report this locale bug).

In Python 2.4 there is a bug on the locale settings, especially on resetting the locale. See http://bugs.python.org/issue504219 for the bug.

So updating the database gave me the error:

[Wed Jan 28 2009 15:59:53] INFO:init:module base: loading security/base_security.xml
[Wed Jan 28 2009 15:59:54] INFO:init:module base: loading maintenance/maintenance_view.xml
[Wed Jan 28 2009 15:59:54] INFO:init:module base: loading security/ir.model.access.csv
[Wed Jan 28 2009 16:00:04] INFO:init:module base: loading translation file for language nl_NL
Traceback (most recent call last):
  File "./openerp-server.py", line 108, in ?
    pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
  File "/opt/server/bin/pooler.py", line 40, in get_db_and_pool
    addons.load_modules(db, force_demo, status, update_module)
  File "/opt/server/bin/addons/__init__.py", line 657, in load_modules
    load_module_graph(cr, basegraph, status, perform_checks=False, report=report)
  File "/opt/server/bin/addons/__init__.py", line 623, in load_module_graph
    modobj.update_translations(cr, 1, [mid], None)
  File "/opt/server/bin/addons/base/module/module.py", line 473, in update_translations
    tools.trans_load(cr.dbname, f, lang, verbose=False)
  File "/opt/server/bin/tools/translate.py", line 504, in trans_load
    r = trans_load_data(db_name, fileobj, fileformat, lang, strict=strict, verbose=verbose)
  File "/opt/server/bin/tools/translate.py", line 570, in trans_load_data
    locale.resetlocale(locale.LC_ALL)
  File "/usr/lib/python2.4/locale.py", line 391, in resetlocale
    _setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting
-bash-3.2$

I'm trying to load the Dutch translation, but this doesn't work.

Go into the python console and do some locale settings on CentOS:

Python 2.4.3 (#1, May 24 2008, 13:47:28)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'utf')
>>> locale._build_localename(locale.getdefaultlocale())
'en_US.utf'
>>> locale.resetlocale
<function resetlocale at 0xb7eb13ac>
>>> locale.resetlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/locale.py", line 391, in resetlocale
    _setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting
>>>

Doing the same on Fedora 10 gave me:

Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'UTF8')
>>> locale._build_localename(locale.getdefaultlocale())
'en_US.UTF8'
>>> locale.resetlocale()
>>>

As you can see, python 2.5 gives me the right encoding, python 2.4 give me the wrong encoding back (utf instead of UTF8).

On this moment I fixed this by backup the locale.py locale.pyo and locale.pyc of python 2.4 and copy the same files from python 2.5 into /usr/lib/python2.4, which fixed this, but it's better to get a workaround in OpenERP.

Revision history for this message
EdbO (edbo-design-deactivatedaccount) wrote :

Updated everything to trunk version:

Tree is up to date at revision 2171.
Tree is up to date at revision 1664.
Tree is up to date at revision 915.
Tree is up to date at revision 2219.

Looks good, BUT after loading the translation file the locale is set to that language. In my case it's Dutch. (don't look at the time, the time on the server isn't correct. It's just a testserver)

[Wed Jan 28 2009 16:25:22] INFO:init:module base: loading security/base_security.xml
[Wed Jan 28 2009 16:25:22] INFO:init:module base: loading maintenance/maintenance_view.xml
[Wed Jan 28 2009 16:25:23] INFO:init:module base: loading security/ir.model.access.csv
[Wed Jan 28 2009 16:25:31] INFO:init:module base: loading translation file for language nl_NL
[wo jan 28 2009 16:26:25] INFO:init:updating modules list
[wo jan 28 2009 16:27:07] INFO:init:module base: loading objects
[wo jan 28 2009 16:27:07] INFO:init:module process: registering objects

This shouldn't be happen.

Revision history for this message
EdbO (edbo-design-deactivatedaccount) wrote :

When the above thing is happen, you will get an error like "could not convert string to float" on different actions (open list, form, create report).

So, after updating the server (./openerp-server -d test --update=all) I stopped the server and did a

bash-3.2$ export LANG=en_US

And then

bash-3.2$ ./openerp-server.py -d test

The translations aren't loaded again, and everything is now working. I even got the thousand-separator in my reports :-) . It didn't came automatically, you have to set this in the language settings in OpenERP. So reporting bugs (you have to dive into the system), will fix some other issues I thought they will never happen :-)

Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

fixed

Changed in openobject-server:
status: New → Fix Released
Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

seem to have a problem with CentOS 5.2

Changed in openobject-server:
status: Fix Released → In Progress
Revision history for this message
Thierry (tboulogne) wrote :

a workaround is to set in /etc/sysconfig/i18n

LANG="fr_FR.utf8" instead of LANG="fr_FR.UTF-8"

and

export LC_ALL="fr_FR.utf8" (i put this line in /root/.bash_profile)

A good restart and it's work for me !

Revision history for this message
Thierry (tboulogne) wrote :

Sorry,

after another reboot the workaround dont' work.

the solution before works right (locale.py of python 2.5).

Revision history for this message
Amit Mendapara (cristatus) wrote :

On my Ubuntu 8.10, python 2.5 returns wrong locale (en_IN.ISO8859-1) which is actually (en_IN.UTF8). So setlocale fails. Here is a patch that tries to set locale without encoding if setlocale fails.

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

I applied AMit's patch. I tested on python2.4 and it works fine.
Reopen if you still have a problem.

Changed in openobject-server:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.