diff --git a/lib/charms/sdcore_nms_k8s/v0/sdcore_config.py b/lib/charms/sdcore_nms_k8s/v0/sdcore_config.py index ebc7816..5411236 100644 --- a/lib/charms/sdcore_nms_k8s/v0/sdcore_config.py +++ b/lib/charms/sdcore_nms_k8s/v0/sdcore_config.py @@ -106,10 +106,10 @@ def _on_sdcore_config_relation_joined(self, event: RelationJoinedEvent): import logging from typing import Optional -from interface_tester.schema_base import DataBagSchema # type: ignore[import] +from interface_tester.schema_base import DataBagSchema from ops.charm import CharmBase, CharmEvents, RelationBrokenEvent, RelationChangedEvent from ops.framework import EventBase, EventSource, Handle, Object -from ops.model import Relation +from ops.model import ModelError, Relation from pydantic import BaseModel, Field, ValidationError # The unique Charmhub library identifier, never change it @@ -120,7 +120,7 @@ def _on_sdcore_config_relation_joined(self, event: RelationJoinedEvent): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 1 +LIBPATCH = 3 logger = logging.getLogger(__name__) @@ -150,7 +150,7 @@ class SdcoreConfigProviderAppData(BaseModel): class ProviderSchema(DataBagSchema): """The schema for the provider side of the sdcore-config interface.""" - app: SdcoreConfigProviderAppData + app_data: SdcoreConfigProviderAppData def data_is_valid(data: dict) -> bool: @@ -163,7 +163,7 @@ def data_is_valid(data: dict) -> bool: bool: True if data is valid, False otherwise. """ try: - ProviderSchema(app=data) + ProviderSchema(app_data=SdcoreConfigProviderAppData(**data)) return True except ValidationError as e: logger.error("Invalid data: %s", e) @@ -207,7 +207,7 @@ class SdcoreConfigRequirerCharmEvents(CharmEvents): class SdcoreConfigRequires(Object): """Class to be instantiated by the SD-Core config requirer charm.""" - on = SdcoreConfigRequirerCharmEvents() + on = SdcoreConfigRequirerCharmEvents() # type: ignore def __init__(self, charm: CharmBase, relation_name: str): """Init.""" @@ -336,4 +336,7 @@ def set_webui_url_in_all_relations(self, webui_url: str) -> None: raise RuntimeError(f"Relation {self.relation_name} not created yet.") for relation in relations: - relation.data[self.charm.app].update({"webui_url": webui_url}) + try: + relation.data[self.charm.app].update({"webui_url": webui_url}) + except ModelError as exc: + logger.error("Error updating the relation data: %s", str(exc))