Fixed scan errors

This commit is contained in:
alexjanousekGSA
2025-06-02 10:44:42 -04:00
parent 07195ba145
commit c8eae375f4
2 changed files with 17 additions and 4 deletions

View File

@@ -63,8 +63,14 @@ def get_notification_by_id(notification_id):
if hasattr(template, "subject"): if hasattr(template, "subject"):
try: try:
notification.__dict__["subject"] = template.subject notification.__dict__["subject"] = template.subject
except Exception: except AttributeError as e:
pass # in case subject is a read-only property current_app.logger.warning(
f"Could not set subject on notification: {e}"
)
except Exception as e:
current_app.logger.error(
f"Unexpected error setting notification subject: {e}"
)
schema = PublicNotificationResponseSchema() schema = PublicNotificationResponseSchema()
schema.context = {"notification_instance": notification} schema.context = {"notification_instance": notification}

View File

@@ -1,6 +1,7 @@
from datetime import datetime, timezone from datetime import datetime, timezone
from uuid import UUID from uuid import UUID
from flask import current_app
from marshmallow import EXCLUDE, Schema, fields, post_dump from marshmallow import EXCLUDE, Schema, fields, post_dump
@@ -122,7 +123,13 @@ class PublicNotificationResponseSchema(PublicNotificationSchema):
elif notification and hasattr(notification, "subject"): elif notification and hasattr(notification, "subject"):
try: try:
data["subject"] = str(notification.subject) data["subject"] = str(notification.subject)
except Exception: except AttributeError:
pass data["subject"] = ""
current_app.logger.debug("Notification has no subject attribute")
except Exception as e:
data["subject"] = ""
current_app.logger.warning(
f"Error getting notification subject: {e}"
)
return data return data