fix(sets): if no set image exists, use nil image

This commit is contained in:
2025-12-05 20:51:41 +01:00
parent 41e61a2f41
commit 1e17185114
4 changed files with 43 additions and 4 deletions
+9
View File
@@ -132,6 +132,15 @@ See [Migration Guide](docs/migration_guide.md) for detailed instructions
- Statistics Query Optimization:
- Replaced separate subqueries with efficient CTEs (Common Table Expressions)
- Consolidated aggregations for set, part, minifigure, and financial statistics
- Add alphanumeric set number support
- Database schema change: Set number column changed from INTEGER to TEXT
- Supports LEGO promotional and special edition sets with letters in their numbers
- Examples: "McDR6US-1", "COMCON035-1", "EG00021-1"
- Add default image handling for sets without images
- Sets with null/missing images from Rebrickable API now display placeholder image
- Automatic fallback to nil.png from parts folder for set previews
- Copy of nil placeholder saved as set image for consistent display across all routes
- Prevents errors when downloading sets that have no set_img_url in API response
### 1.2.4
+22 -1
View File
@@ -53,6 +53,23 @@ class RebrickableImage(object):
if os.path.exists(path):
return
# Check if the original image field is null - copy nil placeholder instead
if self.part is not None and self.part.fields.image is None:
return
if self.minifigure is not None and self.minifigure.fields.image is None:
return
if self.set.fields.image is None:
# Copy nil.png from parts folder to sets folder with set number as filename
parts_folder = current_app.config['PARTS_FOLDER']
if not os.path.isabs(parts_folder):
parts_folder = os.path.join(current_app.root_path, parts_folder)
nil_source = os.path.join(parts_folder, f"{RebrickableImage.nil_name()}.{self.extension}")
if os.path.exists(nil_source):
import shutil
shutil.copy2(nil_source, path)
return
url = self.url()
if url is None:
return
@@ -123,7 +140,11 @@ class RebrickableImage(object):
else:
return self.minifigure.fields.image
return self.set.fields.image
# Handle set images - use nil placeholder if image is null
if self.set.fields.image is None:
return current_app.config['REBRICKABLE_IMAGE_NIL']
else:
return self.set.fields.image
# Return the name of the nil image file
@staticmethod
+11 -2
View File
@@ -155,9 +155,18 @@ class RebrickableSet(BrickRecord):
# Return a short form of the Rebrickable set
def short(self, /, *, from_download: bool = False) -> dict[str, Any]:
# Use nil image URL if set image is null
image_url = self.fields.image
if image_url is None:
# Return path to nil.png from parts folder
image_url = RebrickableImage.static_url(
RebrickableImage.nil_name(),
'PARTS_FOLDER'
)
return {
'download': from_download,
'image': self.fields.image,
'image': image_url,
'name': self.fields.name,
'set': self.fields.set,
}
@@ -207,7 +216,7 @@ class RebrickableSet(BrickRecord):
'year': int(data['year']),
'theme_id': int(data['theme_id']),
'number_of_parts': int(data['num_parts']),
'image': str(data['set_img_url']),
'image': str(data['set_img_url']) if data['set_img_url'] is not None else None,
'url': str(data['set_url']),
'last_modified': str(data['last_modified_dt']),
}
+1 -1
View File
@@ -1,4 +1,4 @@
-- Migration 0019: Performance optimization indexes
-- description: Performance optimization indexes
-- High-impact composite index for problem parts aggregation
-- Used in set listings, statistics, and problem reports