From 1df8c7621fa190016a5aa7d610ebdffc33546b86 Mon Sep 17 00:00:00 2001
From: Mia Altieri <mgaltier200@gmail.com>
Date: Tue, 7 Nov 2023 14:44:32 +0000
Subject: [PATCH] fix logging

---
 lib/charms/mongodb/v0/mongodb_backups.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/charms/mongodb/v0/mongodb_backups.py b/lib/charms/mongodb/v0/mongodb_backups.py
index 972e6884f..9a1aa35cf 100644
--- a/lib/charms/mongodb/v0/mongodb_backups.py
+++ b/lib/charms/mongodb/v0/mongodb_backups.py
@@ -13,7 +13,7 @@
 import re
 import subprocess
 import time
-from typing import Dict, List
+from typing import Dict, List, Optional
 
 from charms.data_platform_libs.v0.s3 import CredentialsChangedEvent, S3Requirer
 from charms.mongodb.v0.helpers import (
@@ -420,11 +420,15 @@ def _wait_pbm_status(self) -> None:
                 except ExecError as e:
                     self.charm.unit.status = BlockedStatus(process_pbm_error(e.stdout))
 
-    def _get_pbm_status(self) -> StatusBase:
+    def _get_pbm_status(self) -> Optional[StatusBase]:
         """Retrieve pbm status."""
         if not self.charm.has_backup_service():
             return WaitingStatus("waiting for pbm to start")
 
+        if not self.model.get_relation(S3_RELATION):
+            logger.info("No configurations for backups, not relation to s3-charm.")
+            return None
+
         try:
             previous_pbm_status = self.charm.unit.status
             pbm_status = self.charm.run_pbm_command(PBM_STATUS_CMD)