diff --git a/data/model/image.py b/data/model/image.py index 8128b9f84..c11e7178b 100644 --- a/data/model/image.py +++ b/data/model/image.py @@ -505,8 +505,15 @@ def find_or_create_derived_storage(source_image, transformation_name, preferred_ uniqueness_hash = _get_uniqueness_hash(varying_metadata) trans = ImageStorageTransformation.get(name=transformation_name) new_storage = storage.create_v1_storage(preferred_location) - DerivedStorageForImage.create(source_image=source_image, derivative=new_storage, - transformation=trans, uniqueness_hash=uniqueness_hash) + + try: + DerivedStorageForImage.create(source_image=source_image, derivative=new_storage, + transformation=trans, uniqueness_hash=uniqueness_hash) + except IntegrityError: + # Storage was created while this method executed. Just return the existing. + new_storage.delete_instance(recursive=True) + return find_derived_storage_for_image(source_image, transformation_name, varying_metadata) + return new_storage