From 04a16af186bae88bc6b85780ab399db5e331bf87 Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Wed, 18 Sep 2024 10:58:13 +0200 Subject: [PATCH 1/2] Revert breaking change in summary.notification introduced in #1060 When introducing bolt 5.5 support for GQL statuses in the summary, the driver gained the ability to polyfill old-style notifications from the statuses. However, `ResultSummary.notifications` used to be `None` when the server didn't send any notifications. When using the polyfill, the field would be set to `[]` instead in the same scenario. This PR fixes this. --- src/neo4j/_work/summary.py | 4 ++-- tests/unit/common/work/test_summary.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/neo4j/_work/summary.py b/src/neo4j/_work/summary.py index 833a6fe68..f605e3c7e 100644 --- a/src/neo4j/_work/summary.py +++ b/src/neo4j/_work/summary.py @@ -175,7 +175,7 @@ def _notification_from_status(status: dict) -> dict: return notification - def _set_notifications(self): + def _set_notifications(self) -> None: if "notifications" in self.metadata: notifications = self.metadata["notifications"] if not isinstance(notifications, list): @@ -197,7 +197,7 @@ def _set_notifications(self): continue notification = self._notification_from_status(status) notifications.append(notification) - self.notifications = notifications + self.notifications = notifications or None return self.notifications = None diff --git a/tests/unit/common/work/test_summary.py b/tests/unit/common/work/test_summary.py index 84c714fab..58adc9c96 100644 --- a/tests/unit/common/work/test_summary.py +++ b/tests/unit/common/work/test_summary.py @@ -1465,7 +1465,7 @@ def test_no_notification_from_status(raw_status, summary_args_kwargs) -> None: summary.summary_notifications ) - assert notifications == [] + assert notifications is None assert summary_notifications == [] @@ -1736,7 +1736,7 @@ def test_no_notification_from_wrong_type_status( notifications = summary.notifications summary_notifications = summary.summary_notifications - assert notifications == [] + assert notifications is None assert summary_notifications == [] @@ -1930,7 +1930,7 @@ def test_no_notification_from_status_without_neo4j_code( notifications = summary.notifications summary_notifications = summary.summary_notifications - assert notifications == [] + assert notifications is None assert summary_notifications == [] @@ -2081,7 +2081,7 @@ def test_notification_from_broken_status( summary = ResultSummary(*args, **kwargs) notifications = summary.notifications - assert notifications == [] + assert notifications is None def test_notifications_from_statuses_keep_order( From 5c4e60babc1c095c17054aeaa34f54023a4bdd19 Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Wed, 18 Sep 2024 14:38:08 +0200 Subject: [PATCH 2/2] TestKit: fake `None` notifications to be `[]` for newer protocol --- testkitbackend/totestkit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testkitbackend/totestkit.py b/testkitbackend/totestkit.py index 1721ea120..f6960ce61 100644 --- a/testkitbackend/totestkit.py +++ b/testkitbackend/totestkit.py @@ -64,7 +64,8 @@ def serialize_notification(n: neo4j.SummaryNotification) -> dict: def serialize_notifications() -> list[dict] | None: if summary_.notifications is None: - return None + gql_aware_protocol = summary_.server.protocol_version >= (5, 5) + return [] if gql_aware_protocol else None return [ serialize_notification(n) for n in summary_.summary_notifications ]