[6.0] All strings must be XML compatible: Unicode or ASCII, no NULL bytes; patch provided

Bug #617484 reported by Raphaël Valyi - http://www.akretion.com
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
New
High
Unassigned

Bug Description

Hello folks,

on v6 (rev #2613) at least, there is an issue if you have some non ASCII chars inside your view. This can be tested, for instance, by installing the l10_br brazilian localization module from here https://code.launchpad.net/~openerp-brazil-team/openerp.pt-br-localiz/trunk

Then click in Localizaçao Brasil > Configuraçao > Fiscal > Codigo de Situaçao Tributaria
you'll get:

[...]
  File "/home/rvalyi/DEV/openerp/server/bin/osv/orm.py", line 2817, in read
    result = self._read_flat(cr, user, select, fields, context, load)
  File "/home/rvalyi/DEV/openerp/server/bin/osv/orm.py", line 2953, in _read_flat
    res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
  File "/home/rvalyi/DEV/openerp/server/bin/osv/fields.py", line 697, in get
    res = self._fnct(obj, cr, user, ids, name, self._arg, context)
  File "/home/rvalyi/DEV/openerp/server/bin/addons/base/ir/ir_actions.py", line 199, in _search_view
    form_arch = self.pool.get(act.res_model).fields_view_get(cr, uid, False, 'form', context)
  File "/home/rvalyi/DEV/openerp/server/bin/osv/orm.py", line 1635, in fields_view_get
    xarch, xfields = self.__view_look_dom_arch(cr, user, result['arch'], view_id, context=context)
  File "/home/rvalyi/DEV/openerp/server/bin/osv/orm.py", line 1297, in __view_look_dom_arch
    fields_def = self.__view_look_dom(cr, user, node, view_id, context=context)
  File "/home/rvalyi/DEV/openerp/server/bin/osv/orm.py", line 1284, in __view_look_dom
    node.set('string', trans)
  File "lxml.etree.pyx", line 634, in lxml.etree._Element.set (src/lxml/lxml.etree.c:31548)
  File "apihelpers.pxi", line 487, in lxml.etree._setAttributeValue (src/lxml/lxml.etree.c:13896)
  File "apihelpers.pxi", line 1242, in lxml.etree._utf8 (src/lxml/lxml.etree.c:19848)
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes

In bin/osv/orm.py, around line 1284, the error occurs because the self.pool.get('ir.translation')._get_source is passing us an unicode object, but because you call .encode('utf8') upon it, you transform it back to a string (read http://evanjones.ca/python-utf8.html if uncomfortable with Python + Unicode) and the Etree node.set API doesn't accept string with non ASCII chars.

Actually all you had to do is just use the unicode value that _get_source passed as in my attached patch. It just works and will also make OpenERP a bit faster here.

Hope this helps.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

There already exists such a bug for stable.
Read at the comment #15 as it clears about the issues.

Thanks.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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