From 48ad832e03c0b9b3b17c42115a3dc810e3477a54 Mon Sep 17 00:00:00 2001 From: Mia Altieri Date: Tue, 25 Jun 2024 11:34:15 +0000 Subject: [PATCH] hot fix for secrets fix --- lib/charms/mongodb/v0/mongodb_secrets.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/charms/mongodb/v0/mongodb_secrets.py b/lib/charms/mongodb/v0/mongodb_secrets.py index 6a1589c6..13d7f058 100644 --- a/lib/charms/mongodb/v0/mongodb_secrets.py +++ b/lib/charms/mongodb/v0/mongodb_secrets.py @@ -6,7 +6,7 @@ from ops import Secret, SecretInfo from ops.charm import CharmBase -from ops.model import SecretNotFoundError +from ops.model import ModelError, SecretNotFoundError from config import Config from exceptions import SecretAlreadyExistsError @@ -93,7 +93,21 @@ def get_content(self) -> Dict[str, str]: """Getting cached secret content.""" if not self._secret_content: if self.meta: - self._secret_content = self.meta.get_content() + try: + self._secret_content = self.meta.get_content(refresh=True) + except (ValueError, ModelError) as err: + # https://bugs.launchpad.net/juju/+bug/2042596 + # Only triggered when 'refresh' is set + known_model_errors = [ + "ERROR either URI or label should be used for getting an owned secret but not both", + "ERROR secret owner cannot use --refresh", + ] + if isinstance(err, ModelError) and not any( + msg in str(err) for msg in known_model_errors + ): + raise + # Due to: ValueError: Secret owner cannot use refresh=True + self._secret_content = self.meta.get_content() return self._secret_content def set_content(self, content: Dict[str, str]) -> None: