Skip to content

Commit

Permalink
storage_thumbnail: always use slugified url_key
Browse files Browse the repository at this point in the history
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 1976597
  • Loading branch information
sebalix committed Jul 9, 2024
1 parent 7b3cda3 commit 3986707
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions storage_thumbnail/models/thumbnail_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 13 additions & 1 deletion storage_thumbnail/tests/test_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def tearDownClass(cls):
cls.loader.restore_registry()
super().tearDownClass()

def _create_thumbnail(self):
def _create_thumbnail(self, **values):
# create thumbnail
vals = {"name": "TEST THUMB"}
vals.update(values)
return self.env["storage.thumbnail"].create(vals)

def _create_image(self, resize=False, **kw):
Expand All @@ -51,6 +52,17 @@ def test_thumbnail(self):
thumb.unlink()
self.assertTrue(file_id.to_delete)

def test_image_get_or_create_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)
Expand Down

0 comments on commit 3986707

Please sign in to comment.