Skip to content

Commit

Permalink
fix relation broken (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim authored Jan 23, 2023
1 parent 953f1a1 commit 968aee5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)

Expand Down Expand Up @@ -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] = {
Expand Down

0 comments on commit 968aee5

Please sign in to comment.