forked from Vauxoo/odoo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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#72395 X-original-commit: a24fe7f Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
- Loading branch information
Showing
5 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters