diff --git a/backend/open_webui/utils/notifications.py b/backend/open_webui/utils/notifications.py index d004af5e70..7d824730de 100644 --- a/backend/open_webui/utils/notifications.py +++ b/backend/open_webui/utils/notifications.py @@ -129,9 +129,10 @@ async def _load_notifications(user_id: str) -> dict[str, Any]: await Users.update_user_settings_by_id(user_id, {'notifications': notifications}) else: notifications['targets'] = [target for target in targets if isinstance(target, dict)] - notifications.setdefault( - 'default_target_id', notifications['targets'][0].get('id') if notifications['targets'] else None - ) + if not notifications.get('default_target_id'): + notifications['default_target_id'] = ( + notifications['targets'][0].get('id') if notifications['targets'] else None + ) if legacy_url and not notifications.get('legacy_notification_events_migrated'): changed = False for target in notifications['targets']: @@ -172,7 +173,8 @@ async def create_target(user_id: str, payload: dict[str, Any]) -> dict[str, Any] suffix += 1 targets.append(target) notifications['targets'] = targets - notifications.setdefault('default_target_id', target['id']) + if not notifications.get('default_target_id'): + notifications['default_target_id'] = target['id'] await Users.update_user_settings_by_id(user_id, {'notifications': notifications}) return _public_target(target, notifications.get('default_target_id'))