diff --git a/lib/charms/data_platform_libs/v0/data_interfaces.py b/lib/charms/data_platform_libs/v0/data_interfaces.py index ddd8f9c9..044bf037 100644 --- a/lib/charms/data_platform_libs/v0/data_interfaces.py +++ b/lib/charms/data_platform_libs/v0/data_interfaces.py @@ -280,6 +280,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent): import json import logging +import os from abc import ABC, ABCMeta, abstractmethod from collections import namedtuple from datetime import datetime @@ -303,7 +304,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 1 +LIBPATCH = 2 logger = logging.getLogger(__name__) @@ -501,11 +502,18 @@ def fetch_relation_data(self) -> dict: This function can be used to retrieve data from a relation in the charm code when outside an event callback. + Function cannot be used in `*-relation-broken` events and will raise an exception. Returns: a dict of the values stored in the relation data bag for all relation instances (indexed by the relation ID). """ + if "-relation-broken" in os.environ.get("JUJU_HOOK_NAME", ""): + # read more in https://bugs.launchpad.net/juju/+bug/1960934 + raise RuntimeError( + "`fetch_relation_data` cannot be used in `*-relation-broken` events" + ) + data = {} for relation in self.relations: data[relation.id] = {