From b8d25707250f37be9d6ff7c141094fcaa96ce990 Mon Sep 17 00:00:00 2001 From: Joseph Schorr <josephschorr@users.noreply.github.com> Date: Tue, 19 Jul 2016 16:44:05 -0400 Subject: [PATCH] Don't raise an error on duplicate placements This can happen if two pushes are racing on the same storage. --- data/model/storage.py | 5 ++++- workers/storagereplication.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/model/storage.py b/data/model/storage.py index 1f7932932..109b7a888 100644 --- a/data/model/storage.py +++ b/data/model/storage.py @@ -39,7 +39,10 @@ def get_image_location_for_id(location_id): def add_storage_placement(storage, location_name): """ Adds a storage placement for the given storage at the given location. """ location = get_image_location_for_name(location_name) - ImageStoragePlacement.create(location=location.id, storage=storage) + try: + ImageStoragePlacement.create(location=location.id, storage=storage) + except IntegrityError: + # Placement already exists. Nothing to do. def garbage_collect_storage(storage_id_whitelist): diff --git a/workers/storagereplication.py b/workers/storagereplication.py index 627ae9137..afdc17c71 100644 --- a/workers/storagereplication.py +++ b/workers/storagereplication.py @@ -46,7 +46,6 @@ class StorageReplicationWorker(QueueWorker): return True # For any missing storage locations, initiate a copy. - storage_paths = StoragePaths() existing_location = list(partial_storage.locations)[0] for location in locations_missing: