Skip to content

Commit

Permalink
Use delete w/ obj store mgr create() if add fails.
Browse files Browse the repository at this point in the history
Fixing ObjectStoreDatasetManager create() function so that it calls the
delete() function if initial data fails to be added (and thus the
dataset does not need to end up created); previous logic that just
removed the bucket would fail if the bucket had anything in it.
  • Loading branch information
robertbartel committed Jul 11, 2023
1 parent 7ee2fe8 commit 16f17cd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions python/lib/modeldata/dmod/modeldata/data/object_store_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,24 @@ def create(self, name: str, category: DataCategory, domain: DataDomain, is_read_
dataset = Dataset(name=name, category=category, data_domain=domain, dataset_type=DatasetType.OBJECT_STORE,
manager=self, access_location=access_loc, is_read_only=is_read_only, created_on=created_on,
last_updated=created_on, expires_on=expires_on)

# Once dataset is added to ``datasets``, it's "managed," so calls to add_data, delete, etc., should work
self.datasets[name] = dataset

# Put in a try block to make sure the dataset only remains if adding data worked as needed (if applicable)
try:
if initial_data is not None:
initial_data.add_initial_data()

# TODO: (later) consider whether dataset should not be deleted if everything else worked until this
# Then updated the persisted state file and return
self.persist_serialized(name)

return dataset
# If we ran into any trouble writing initial data to the dataset, then bail, cleaning up the dataset from the
# manager and the object store itself
# If we ran into any trouble adding initial data, then bail, cleaning up the dataset and backing storage
except Exception as e:
self.datasets.pop(name)
self._client.remove_bucket(name)
# Since the dataset is "managed," we can call delete()
self.delete(dataset=dataset)
raise e

@property
Expand Down

0 comments on commit 16f17cd

Please sign in to comment.