Fix duplicate derived storage cache creation issue

Fixes #1699
This commit is contained in:
Joseph Schorr 2016-08-10 16:15:46 -04:00
parent 4ecf763446
commit 34d49e2d44

View file

@ -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