From 4da3cead7dbaf1ba36540653481338386025d6ea Mon Sep 17 00:00:00 2001 From: Antoine Mineau Date: Tue, 17 Oct 2023 16:26:00 +0200 Subject: [PATCH] fix: viewpoint has no snapshot --- webhooks/handlers.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/webhooks/handlers.py b/webhooks/handlers.py index 3dee5e1..4166a21 100644 --- a/webhooks/handlers.py +++ b/webhooks/handlers.py @@ -41,10 +41,16 @@ def _refresh_bcf(self, save: bool) -> None: ) except Exception: viewpoints = [] - if len(viewpoints) > 0: - self.notification.payload["topic"]["snapshot_url"] = viewpoints[0][ - "snapshot" - ]["snapshot_data"] + snapshot_data = next( + ( + viewpoint["snapshot"]["snapshot_data"] + for viewpoint in viewpoints + if viewpoint["snapshot"] + ), + None, + ) + if snapshot_data: + self.notification.payload["topic"]["snapshot_url"] = snapshot_data if save: self.notification.save()