Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notification polyfill from incomplete GQL status #1080

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 30 additions & 46 deletions src/neo4j/_work/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ def __getattr__(self, key):
f"'{self.__class__.__name__}' object has no attribute '{key}'"
)

@staticmethod
def _notification_from_status(status: dict) -> dict:
notification = {}
for notification_key, status_key in (
("title", "title"),
("code", "neo4j_code"),
("description", "description"),
):
if status_key in status:
notification[notification_key] = status[status_key]

if "diagnostic_record" in status:
diagnostic_record = status["diagnostic_record"]
if not isinstance(diagnostic_record, dict):
diagnostic_record = {}

for notification_key, diag_record_key in (
("severity", "_severity"),
("category", "_classification"),
("position", "_position"),
):
if diag_record_key in diagnostic_record:
notification[notification_key] = \
diagnostic_record[diag_record_key]

return notification

def _set_notifications(self):
if "notifications" in self.metadata:
notifications = self.metadata["notifications"]
Expand All @@ -156,53 +183,10 @@ def _set_notifications(self):
return
notifications = []
for status in statuses:
if not isinstance(status, dict):
continue
notification = {}
failed = False
for notification_key, status_key in (
("title", "title"),
("code", "neo4j_code"),
("description", "description"),
):
value = status.get(status_key)
if not isinstance(value, str) or not value:
failed = True
break
notification[notification_key] = value
if failed:
continue
diagnostic_record = status.get("diagnostic_record")
if not isinstance(diagnostic_record, dict):
continue
for notification_key, diag_record_key in (
("severity", "_severity"),
("category", "_classification"),
):
value = diagnostic_record.get(diag_record_key)
if not isinstance(value, str) or not value:
failed = True
break
notification[notification_key] = value
if failed:
continue
raw_position = diagnostic_record.get("_position")
if not isinstance(raw_position, dict):
continue
position = {}
for pos_key, raw_pos_key in (
("line", "line"),
("column", "column"),
("offset", "offset"),
):
value = raw_position.get(raw_pos_key)
if not isinstance(value, int) or isinstance(value, bool):
failed = True
break
position[pos_key] = value
if failed:
if not (isinstance(status , dict) and "neo4j_code" in status):
# not a notification status
continue
notification["position"] = position
notification = self._notification_from_status(status)
notifications.append(notification)
self.notifications = notifications
return
Expand Down
Loading