-
- Downloads
[FIX] core: don't break import on files triggering UnicodeEncodeError
The import logging (ish) assumes that if an exception has at least 2
args the second arg is metadata added by the callee.
As it turns out, `UnicodeEncodeError` has *five* arguments, none of
which is added by us. So if encoding something fails during the
process (e.g. because the file contains a lone surrogate, which leads
to the database insert failing when psycopg2 tries to encode the query
to UTF8), then the `_log` function itself will fail, yielding a very
unhelpful error of:
dictionary update sequence element #0 has length 1; 2 is required
(because we tried to update a dict using a string).
This issue occurs only during *field conversion* and most fields have
no need to interact with the database (so don't need to encode the
value, which is what fails), however it is a problem when the invalid
string is used as a record name to look for (e.g. an m2o).
Further improve the experience by converting the UnicodeEncodeError to
a ValueError using the stringified UEE: `_log` assumes the first
argument to the exception is an error message of some sort, but for
UnicodeError subclasses it's just the encoding involved in the
error (here `utf-8`), which doesn't really serve as an error message.
Stringifying the exception generates a complete error message which is
quite a bit more helpful.
Issue 2480064
closes odoo/odoo#72398
X-original-commit: a24fe7ff06a03e4a4b477b30ee3feb0ec06a7d0a
Signed-off-by:
Xavier Morel (xmo) <xmo@odoo.com>
Showing
- odoo/addons/base/models/ir_fields.py 2 additions, 1 deletionodoo/addons/base/models/ir_fields.py
- odoo/addons/test_impex/ir.model.access.csv 2 additions, 0 deletionsodoo/addons/test_impex/ir.model.access.csv
- odoo/addons/test_impex/models.py 10 additions, 0 deletionsodoo/addons/test_impex/models.py
- odoo/addons/test_impex/tests/test_load.py 14 additions, 0 deletionsodoo/addons/test_impex/tests/test_load.py
- odoo/models.py 1 addition, 1 deletionodoo/models.py
Loading
Please register or sign in to comment