From 8807accf6b777e9a9101848ad808809c369b57fa Mon Sep 17 00:00:00 2001 From: Neha Oudin Date: Mon, 14 Oct 2024 17:18:03 +0200 Subject: [PATCH] fix: export fallback out of get The dictionary can have a None value in case there's no snapshot: pbm status can contain a `null` value for pbm[backups][snapshot] which is parsed as None and then `pbm_status["backups"].get("snapshot", []) == None` which is not what is expected here. --- lib/charms/mongodb/v1/mongodb_backups.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/charms/mongodb/v1/mongodb_backups.py b/lib/charms/mongodb/v1/mongodb_backups.py index c15e5bafe..559242f67 100644 --- a/lib/charms/mongodb/v1/mongodb_backups.py +++ b/lib/charms/mongodb/v1/mongodb_backups.py @@ -41,7 +41,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 5 +LIBPATCH = 6 logger = logging.getLogger(__name__) @@ -800,7 +800,7 @@ def get_backup_error_status(self, backup_id: str) -> str: """Get the error status for a provided backup.""" pbm_status = self.charm.run_pbm_command(["status", "--out=json"]) pbm_status = json.loads(pbm_status) - backups = pbm_status["backups"].get("snapshot", []) + backups = pbm_status["backups"].get("snapshot") or [] for backup in backups: if backup_id == backup["name"]: return backup.get("error", "")