diff --git a/backend/services/image_storage.py b/backend/services/image_storage.py index 5c19f4f6..f20dce8a 100644 --- a/backend/services/image_storage.py +++ b/backend/services/image_storage.py @@ -84,8 +84,10 @@ def get_unique_filename( # Build the base filename without UUID base_filename = f"{sanitized_name}_{variant}.jpg" - # Check for collision (existing_files should already be lowercased) - if base_filename.lower() not in existing_files: + # Defensive collision check: handle both pre-lowercased and any-case input + # This maintains backward compatibility while supporting the optimization + existing_lower = [f.lower() for f in existing_files] + if base_filename.lower() not in existing_lower: # No collision return base_filename