Skip to content

Commit

Permalink
fix bug in role retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Sep 25, 2023
1 parent 059356f commit 12e51f6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@ def db_initialised(self) -> bool:
@property
def role(self) -> str:
"""Returns role of MongoDB deployment."""
if "role" not in self.app_peer_data and self.unit.is_leader():
if (
"role" not in self.app_peer_data
and self.unit.is_leader()
and self.model.config["role"]
):
self.app_peer_data["role"] = self.model.config["role"]
# app data bag isn't set until function completes
return self.model.config["role"]
else:
# if leader hasn't set the role yet, use the one set by model
self.model.config["role"]
return self.model.config["role"]

return self.app_peer_data.get("role")

Expand Down Expand Up @@ -563,7 +569,7 @@ def _on_get_primary_action(self, event: ActionEvent):
def _on_get_password(self, event: ActionEvent) -> None:
"""Returns the password for the user as an action response."""
username = self._get_user_or_fail_event(
event, default_username=OperatorUser.get_username()
event, default_username=f"OperatorUser.get_username()"
)
if not username:
return
Expand All @@ -590,7 +596,7 @@ def _on_set_password(self, event: ActionEvent) -> None:
return

username = self._get_user_or_fail_event(
event, default_username=OperatorUser.get_username()
event, default_username=f"OperatorUser.get_username()"
)
if not username:
return
Expand Down

0 comments on commit 12e51f6

Please sign in to comment.