From a610e9be3784169a9998fe7868656fdc998f581b Mon Sep 17 00:00:00 2001 From: Mia Altieri Date: Tue, 10 Oct 2023 08:58:17 +0000 Subject: [PATCH] cannot comput diff on departed events --- lib/charms/mongodb/v0/mongodb_provider.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/charms/mongodb/v0/mongodb_provider.py b/lib/charms/mongodb/v0/mongodb_provider.py index b84419be2..1056eb445 100644 --- a/lib/charms/mongodb/v0/mongodb_provider.py +++ b/lib/charms/mongodb/v0/mongodb_provider.py @@ -123,9 +123,8 @@ def _on_relation_event(self, event): departed_relation_id = None if type(event) is RelationBrokenEvent: - departed_relation_id = event.relation.id - # Only relation_deparated events can check if scaling down + departed_relation_id = event.relation.id if not self.charm.has_departed_run(departed_relation_id): logger.info( "Deferring, must wait for relation departed hook to decide if relation should be removed." @@ -134,12 +133,16 @@ def _on_relation_event(self, event): return # check if were scaling down and add a log message - if self.charm.is_scaling_down(event.relation.id): + if self.charm.is_scaling_down(departed_relation_id): logger.info( "Relation broken event occurring due to scale down, do not proceed to remove users." ) return + logger.info( + "Relation broken event occurring due to relation removal, proceed to remove user." + ) + try: self.oversee_users(departed_relation_id, event) except PyMongoError as e: @@ -214,6 +217,9 @@ def _diff(self, event: RelationChangedEvent) -> Diff: a Diff instance containing the added, deleted and changed keys from the event relation databag. """ + if not isinstance(event, RelationChangedEvent): + logger.info("Cannot compute diff of event type: %s", type(event)) + return # TODO import marvelous unit tests in a future PR # Retrieve the old data from the data key in the application relation databag. old_data = json.loads(event.relation.data[self.charm.model.app].get("data", "{}"))