Skip to content

Commit

Permalink
cannot comput diff on departed events
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Oct 10, 2023
1 parent 08e6b60 commit a610e9b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/charms/mongodb/v0/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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:
Expand Down Expand Up @@ -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", "{}"))
Expand Down

0 comments on commit a610e9b

Please sign in to comment.