From 8425a21d7212e6bf7b65049c742d1bc7a3597200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Tue, 9 Jul 2024 16:21:51 +0200 Subject: [PATCH] storage_thumbnail: always use slugified url_key Both for creating and searching thumbnails. This avoid an infinite creation of thumbnails on images as soon as an `url_key` is provided. This is a regression introduced by commit 197659721718024b520c2ff364bd97b15dfc0b4b --- storage_thumbnail/models/thumbnail_mixin.py | 1 + storage_thumbnail/tests/test_thumbnail.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/storage_thumbnail/models/thumbnail_mixin.py b/storage_thumbnail/models/thumbnail_mixin.py index 2db06aff65..736eb09647 100644 --- a/storage_thumbnail/models/thumbnail_mixin.py +++ b/storage_thumbnail/models/thumbnail_mixin.py @@ -101,6 +101,7 @@ def get_existing_thumbnail(self, size_x, size_y, url_key=None): return thumbnail def get_or_create_thumbnail(self, size_x, size_y, url_key=None): + url_key = self._get_url_key(url_key) thumbnail = self.get_existing_thumbnail(size_x, size_y, url_key=url_key) if not thumbnail and self.data: vals = self.env["storage.thumbnail"]._prepare_thumbnail( diff --git a/storage_thumbnail/tests/test_thumbnail.py b/storage_thumbnail/tests/test_thumbnail.py index 44bacbb7ba..1550f2aeaa 100644 --- a/storage_thumbnail/tests/test_thumbnail.py +++ b/storage_thumbnail/tests/test_thumbnail.py @@ -51,6 +51,17 @@ def test_thumbnail(self): thumb.unlink() self.assertTrue(file_id.to_delete) + def test_image_get_existing_thumbnail(): + image = self._create_image() + self.assertTrue(image.url) + self.assertEqual(2, len(image.thumbnail_ids)) + thumb = image.thumb_small_id + thumb.url_key = "test" + existing_thumb = image.get_existing_thumbnail( + thumb.size_x, thumb.size_y, url_key="TEST" + ) + self.assertEqual(thumb, existing_thumb) + def test_model(self): image = self._create_image() self.assertTrue(image.url)