From ccfafd9c5f629d0353eee2963320b0f72dd11df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=95=E8=B0=B7=E9=85=B1?= <74496778+GooGuJiang@users.noreply.github.com> Date: Sun, 24 Aug 2025 21:45:07 +0800 Subject: [PATCH] Add fallback for user avatar URL in notifications Ensures that a default avatar URL is used if the user object lacks an avatar_url attribute or if an exception occurs, improving robustness of notification cover images. --- app/models/notification.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/notification.py b/app/models/notification.py index dbfcaa3..dd7aaa9 100644 --- a/app/models/notification.py +++ b/app/models/notification.py @@ -117,10 +117,14 @@ class ChannelMessageBase(NotificationDetail): receiver: list[int], channel_type: "ChannelType", ) -> Self: + try: + avatar_url = getattr(user, 'avatar_url', 'https://lazer-data.g0v0.top/default.jpg') or 'https://lazer-data.g0v0.top/default.jpg' + except Exception: + avatar_url = 'https://lazer-data.g0v0.top/default.jpg' instance = cls( title=truncate(message.content, CONTENT_TRUNCATE), type=channel_type.value.lower(), - cover_url=user.avatar_url, + cover_url=avatar_url, ) instance._message = message instance._user = user