From d615c5bfaa0d11fc712e2cf540594b207198b0d4 Mon Sep 17 00:00:00 2001 From: Sanket Brahmbhatt Date: Mon, 24 Apr 2023 11:27:30 +0000 Subject: [PATCH] [FIX] base_import: prevent trackback while upload unidentified image URL This issue occurs when a customer imports or uploads a file, and that file contains an image that is attached to the URL as text or HTML. then, The error would be generated. Step to Produce:- - import CSV file (Ex.'product.product' model) > that CSV file must have one URL Image(In that URL has content of text or Html form) - Click On the 'Test' Button. Applying these changes will resolve this issue. sentry:-4046190590 closes odoo/odoo#137611 X-original-commit: acbb5af7ee96cdc579850427bc2bca6d7bf184e4 Signed-off-by: Achraf Ben Azzouz (abz) --- addons/base_import/models/base_import.py | 15 +++++++-------- addons/web_editor/models/ir_qweb_fields.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/base_import/models/base_import.py b/addons/base_import/models/base_import.py index c2714e2864f..48d75aba83a 100644 --- a/addons/base_import/models/base_import.py +++ b/addons/base_import/models/base_import.py @@ -1263,14 +1263,13 @@ class Import(models.TransientModel): return base64.b64encode(content) except Exception as e: - _logger.exception(e) - raise ImportValidationError( - _( - "Could not retrieve URL: %(url)s [%(field_name)s: L%(line_number)d]: %(error)s", - url=url, field_name=field, line_number=line_number + 1, error=e - ), - field=field - ) + _logger.warning(e, exc_info=True) + raise ValueError(_("Could not retrieve URL: %(url)s [%(field_name)s: L%(line_number)d]: %(error)s") % { + 'url': url, + 'field_name': field, + 'line_number': line_number + 1, + 'error': e + }) def execute_import(self, fields, columns, options, dryrun=False): """ Actual execution of the import diff --git a/addons/web_editor/models/ir_qweb_fields.py b/addons/web_editor/models/ir_qweb_fields.py index 3cccf091d53..98b5ea89d4a 100644 --- a/addons/web_editor/models/ir_qweb_fields.py +++ b/addons/web_editor/models/ir_qweb_fields.py @@ -517,7 +517,7 @@ class Image(models.AbstractModel): # force a complete load of the image data to validate it image.load() except Exception: - logger.exception("Failed to load remote image %r", url) + logger.warning("Failed to load remote image %r", url, exc_info=True) return None # don't use original data in case weird stuff was smuggled in, with