fix: a new notification target becomes the default after the last one was removed (#33284)

This commit is contained in:
G30 2026-10-28 13:58:45 -04:00 • committed by GitHub
parent fcc9284139
commit 77398eba31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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'))