From 156e38af2055debed9a673c56bd0c710704834a2 Mon Sep 17 00:00:00 2001
From: Petr Jasek <jasekpetr@gmail.com>
Date: Wed, 3 Apr 2024 15:12:24 +0200
Subject: [PATCH] log error for events from Onclusive with empty name

SDCP-754
---
 server/planning/feed_parsers/onclusive.py       |  5 ++++-
 server/planning/feed_parsers/onclusive_tests.py | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/server/planning/feed_parsers/onclusive.py b/server/planning/feed_parsers/onclusive.py
index 5539ec011..ee4241e18 100644
--- a/server/planning/feed_parsers/onclusive.py
+++ b/server/planning/feed_parsers/onclusive.py
@@ -79,7 +79,7 @@ def parse(self, content, provider=None):
             except EmbargoedException:
                 logger.info("Ignoring embargoed event %s", event["itemId"])
             except Exception as error:
-                logger.exception("error %s when parsing event %s", error, event["itemId"], extra=dict(event=event))
+                logger.exception("Error when parsing Onclusive event", extra=dict(event=event, error=str(error)))
         return all_events
 
     def set_occur_status(self, item):
@@ -108,6 +108,9 @@ def parse_item_meta(self, event, item):
             event["description"] if (event["summary"] != "" and event["summary"] is not None) else ""
         )
 
+        if not item["name"]:
+            raise ValueError("Event name is empty")
+
         item["links"] = [event[key] for key in ("website", "website2") if event.get(key)]
         if event.get("locale"):
             item["language"] = event["locale"].split("-")[0]
diff --git a/server/planning/feed_parsers/onclusive_tests.py b/server/planning/feed_parsers/onclusive_tests.py
index 120933ab6..1c6df9526 100644
--- a/server/planning/feed_parsers/onclusive_tests.py
+++ b/server/planning/feed_parsers/onclusive_tests.py
@@ -4,6 +4,7 @@
 import logging
 import datetime
 import superdesk
+import pytest
 
 from planning.tests import TestCase
 from superdesk.metadata.item import (
@@ -187,3 +188,12 @@ def test_timezone_ambigous_time_error(self):
 
         item = OnclusiveFeedParser().parse([data])[0]
         assert item["dates"]["tz"] == "Asia/Tokyo"
+
+    def test_error_on_empty_name(self):
+        data = self.data.copy()
+        data["summary"] = ""
+        data["description"] = ""
+
+        with self.assertLogs("planning", level=logging.ERROR) as logger:
+            OnclusiveFeedParser().parse([data])
+            assert "Error when parsing Onclusive event" in logger.output[0]