From c8eae375f472caed37255b68ae79bf6f1d1e6a9c Mon Sep 17 00:00:00 2001 From: alexjanousekGSA Date: Mon, 2 Jun 2025 10:44:42 -0400 Subject: [PATCH] Fixed scan errors --- app/notifications/rest.py | 10 ++++++++-- app/public_schemas/public.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 4f3b7eb77..96836714e 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -63,8 +63,14 @@ def get_notification_by_id(notification_id): if hasattr(template, "subject"): try: notification.__dict__["subject"] = template.subject - except Exception: - pass # in case subject is a read-only property + except AttributeError as e: + 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.context = {"notification_instance": notification} diff --git a/app/public_schemas/public.py b/app/public_schemas/public.py index fc7d66974..d067e1262 100644 --- a/app/public_schemas/public.py +++ b/app/public_schemas/public.py @@ -1,6 +1,7 @@ from datetime import datetime, timezone from uuid import UUID +from flask import current_app from marshmallow import EXCLUDE, Schema, fields, post_dump @@ -122,7 +123,13 @@ class PublicNotificationResponseSchema(PublicNotificationSchema): elif notification and hasattr(notification, "subject"): try: data["subject"] = str(notification.subject) - except Exception: - pass + except AttributeError: + 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