From 59a3f75b10cb8945afbdf385742b44dfd6b1e37f Mon Sep 17 00:00:00 2001 From: Sanket Brahmbhatt <sabr@odoo.com> Date: Tue, 11 Apr 2023 10:57:20 +0000 Subject: [PATCH] [FIX] base,tools: raise usererror instead of a valueerror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This issue is generated when the user uploads an image of more than 50.0 million pixels, so error would be generated. But, currently it raises a `ValueError` which results in traceback. So, we replace it with `UserError` so the user has an idea about Image size or pixel being excessive. closes odoo/odoo#118281 Sentry: - 4075426049 Signed-off-by: Rémy Voet <ryv@odoo.com> --- odoo/addons/base/tests/test_image.py | 2 +- odoo/tools/image.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/tests/test_image.py b/odoo/addons/base/tests/test_image.py index 1b92a829e358..48fc10f9bf76 100644 --- a/odoo/addons/base/tests/test_image.py +++ b/odoo/addons/base/tests/test_image.py @@ -166,7 +166,7 @@ class TestImage(TransactionCase): res = tools.image_process(self.base64_1920x1080_jpeg, verify_resolution=True) self.assertNotEqual(res, False, "size ok") base64_image_excessive = tools.image_to_base64(Image.new('RGB', (50001, 1000)), 'PNG') - with self.assertRaises(ValueError, msg="size excessive"): + with self.assertRaises(UserError, msg="size excessive"): tools.image_process(base64_image_excessive, verify_resolution=True) def test_13_image_process_quality(self): diff --git a/odoo/tools/image.py b/odoo/tools/image.py index e70303bba1ea..ecbab85fc0e7 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -90,7 +90,7 @@ class ImageProcess(): w, h = self.image.size if verify_resolution and w * h > IMAGE_MAX_RESOLUTION: - raise ValueError(_("Image size excessive, uploaded images must be smaller than %s million pixels.", str(IMAGE_MAX_RESOLUTION / 1e6))) + raise UserError(_("Image size excessive, uploaded images must be smaller than %s million pixels.", str(IMAGE_MAX_RESOLUTION / 1e6))) def image_quality(self, quality=0, output_format=''): """Return the image resulting of all the image processing -- GitLab