[FIX] base_import: prevent traceback if image data contains non ASCII characters
When user tries to add non ascii characters in image field column in a file and then when he tries to import it the error will occur. Steps to reproduce: 1. Install contacts 2. export a contact and keep image field in fields to export. 3. Now in that file change the image data and add non ASCII characters (for example: 'ô'). 4. Now try to import this file in contacts. 5. The error will occur. Applying this commit will fix this issue. Currently, a ValueError is raised when we give non-ascii characters as input. So I have reported an issue in python in which I have mentioned to edit the documentation to note that it may raise ValueError for non-ascii content, or to fix '_bytes_from_decode_data' function to raise binascii.Error instead of ValueError. To track the issue - https://github.com/python/cpython/issues/105193 sentry-4029823200 closes odoo/odoo#123572 X-original-commit: ceb67160e1747f0a886efb8ca0a60499e2b080d1 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -1184,7 +1184,7 @@ class Import(models.TransientModel):
|
||||
else:
|
||||
try:
|
||||
base64.b64decode(line[index], validate=True)
|
||||
except binascii.Error:
|
||||
except ValueError:
|
||||
raise ImportValidationError(
|
||||
_("Found invalid image data, images should be imported as either URLs or base64-encoded data."),
|
||||
field=name, field_type=field['type']
|
||||
|
||||
Reference in New Issue
Block a user