Skip to content

Commit

Permalink
fix: export fallback out of get
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gu1nness committed Oct 14, 2024
1 parent b1e75fd commit 8807acc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/charms/mongodb/v1/mongodb_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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", "")
Expand Down

0 comments on commit 8807acc

Please sign in to comment.