From 2d70761dcaf1b7adbc63ac6f157dc4ad13636d39 Mon Sep 17 00:00:00 2001 From: Sanket Brahmbhatt 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#121396 Sentry: - 4075426049 X-original-commit: ac2a3966cb035f112bf6aebb1244dc8d67831d1a Signed-off-by: Rémy Voet --- 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 9db2b9e2e52..3acf6249883 100644 --- a/odoo/addons/base/tests/test_image.py +++ b/odoo/addons/base/tests/test_image.py @@ -157,7 +157,7 @@ class TestImage(TransactionCase): res = tools.image_process(self.img_1920x1080_jpeg, verify_resolution=True) self.assertNotEqual(res, False, "size ok") image_excessive = tools.image_apply_opt(Image.new('RGB', (50001, 1000)), 'PNG') - with self.assertRaises(ValueError, msg="size excessive"): + with self.assertRaises(UserError, msg="size excessive"): tools.image_process(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 a4d8e4604de..1bf10e8d1f0 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -91,7 +91,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