From 13fe83faed6c5c57a721c25b67d48053b9692403 Mon Sep 17 00:00:00 2001 From: Job Doesburg Date: Wed, 24 Jul 2024 10:47:45 +0200 Subject: [PATCH] Fix Source.DoesNotExist after migrating ImageField (#123) --- thumbnails/backends/metadata.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/thumbnails/backends/metadata.py b/thumbnails/backends/metadata.py index 0f1dde5..eea5efb 100644 --- a/thumbnails/backends/metadata.py +++ b/thumbnails/backends/metadata.py @@ -76,7 +76,12 @@ def get_thumbnail(self, source_name, size): return None def add_thumbnail(self, source_name, size, name): - source = self.get_source(source_name) + try: + source = self.get_source(source_name) + except Source.DoesNotExist: + # If the source doesn't exist, create it + # For example when migrating from a regular ImageField to a thumbnailed ImageField + source = self.add_source(source_name) meta = ThumbnailMeta.objects.create(source=source, size=size, name=name) return ImageMeta(source_name, meta.name, meta.size)