Skip to content

Commit

Permalink
Use Storage.index instead of deprecated Storage.id (#854)
Browse files Browse the repository at this point in the history
The Storage.id attributes was deprecated in PR #734, but this usage of
it wasn't updated, so we were getting WARNING logs about it.

Fixes #853
  • Loading branch information
benhoyt authored Nov 16, 2022
1 parent da4a0ec commit 5f46da6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ops/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ def _get_event_args(charm: 'CharmBase',
storage_name = "-".join(bound_event.event_kind.split("_")[:-2])

storages = model.storages[storage_name]
id, storage_location = model._backend._storage_event_details()
index, storage_location = model._backend._storage_event_details()
if len(storages) == 1:
storage = storages[0]
else:
# If there's more than one value, pick the right one. We'll realize the key on lookup
storage = next((s for s in storages if s.id == id), None)
storage = next((s for s in storages if s.index == index), None)
storage = cast(Union[ops.storage.JujuStorage, ops.storage.SQLiteStorage], storage)
storage.location = storage_location # type: ignore
return [storage], {}
Expand Down
4 changes: 2 additions & 2 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,9 +2392,9 @@ def _storage_event_details(self) -> Tuple[int, str]:
raise RuntimeError('unable to find storage key in {output!r}'.format(output=output))
key = match.groupdict()["storage_key"]

id = int(key.split("/")[1])
index = int(key.split("/")[1])
location = self.storage_get(key, "location")
return id, location
return index, location

def storage_get(self, storage_name_id: str, attribute: str) -> str:
if not len(attribute) > 0: # assume it's an empty string.
Expand Down

0 comments on commit 5f46da6

Please sign in to comment.