{"record":{"id":"37e197c165b0c44d","repo":"open-webui/open-webui","slug":"default-calendar-cannot-be-deleted","errorCode":null,"errorMessage":"Default calendar cannot be deleted","messagePattern":"Default calendar cannot be deleted","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"backend/open_webui/routers/calendar.py","lineNumber":451,"sourceCode":"\n\n@router.delete('/{calendar_id}/delete')\nasync def delete_calendar(request: Request, calendar_id: str, user: UserModel = Depends(get_verified_user)):\n    await check_calendar_permission(request, user)\n\n    # Block deletion of the virtual Scheduled Tasks calendar\n    if calendar_id == SCHEDULED_TASKS_CALENDAR_ID:\n        raise HTTPException(status_code=400, detail='System calendars cannot be deleted')\n\n    cal = await _check_calendar_access(calendar_id, user, 'write')\n\n    # Only owner/admin can delete\n    if cal.user_id != user.id and user.role != 'admin':\n        raise HTTPException(status_code=403, detail='Only owner can delete calendar')\n\n    # Block deletion of default calendar\n    if cal.is_default:\n        raise HTTPException(status_code=400, detail='Default calendar cannot be deleted')\n\n    result = await Calendars.delete_calendar_by_id(calendar_id)\n    if not result:\n        raise HTTPException(status_code=500, detail='Failed to delete')\n    await publish_event(\n        request,\n        EVENTS.CALENDAR_DELETED,\n        actor=user,\n        subject_id=calendar_id,\n        data={'name': cal.name},\n    )\n    return {'status': True}\n\n\n@router.post('/{calendar_id}/default')\nasync def set_default_calendar(request: Request, calendar_id: str, user: UserModel = Depends(get_verified_user)):\n    await check_calendar_permission(request, user)\n    cal = await Calendars.set_default_calendar(user.id, calendar_id)","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/open-webui/open-webui/blob/01f4282f1ffe0d6212f58d3afbeae21fffd0c4be/backend/open_webui/routers/calendar.py#L433-L469","documentation":"DELETE /api/v1/calendars/{calendar_id}/delete: the calendar exists and the requester is owner/admin, but cal.is_default is true. Each user's default calendar cannot be deleted; it must first be demoted by setting another calendar as default (POST /{calendar_id}/default).","triggerScenarios":"Owner deletes their only remaining calendar (which is the default); deleting the auto-created default calendar without first creating/promoting another; bulk delete that includes the default calendar id.","commonSituations":"New users cleaning up initial calendars; scripts pruning all calendars; UI not surfacing which calendar is default.","solutions":["Create or pick another calendar, then POST /api/v1/calendars/{other_id}/default to transfer the default flag.","Retry the delete on the former default calendar.","In bulk-delete flows, skip is_default calendars or reorder operations so a new default is set first."],"exampleFix":"// before\nawait api.delete(`/calendars/${id}/delete`);\n// after\nif (calendar.is_default) {\n  await api.post(`/calendars/${otherId}/default`);\n}\nawait api.delete(`/calendars/${id}/delete`);","handlingStrategy":"validation","validationCode":"if (calendar.is_default) {\n  const fallback = calendars.find(c => c.id !== calendar.id && c.user_id === currentUser.id);\n  if (!fallback) throw new Error('Create another calendar before deleting the default');\n  await api.post(`/api/v1/calendars/${fallback.id}/default`);\n}\nawait api.delete(`/api/v1/calendars/${calendar.id}/delete`);","typeGuard":"function isDefaultCalendar(c: { is_default?: boolean } | null | undefined): boolean {\n  return !!c?.is_default;\n}","tryCatchPattern":"try {\n  await api.delete(`/api/v1/calendars/${id}/delete`);\n} catch (e) {\n  if (e?.status === 400 && e?.detail === 'Default calendar cannot be deleted') {\n    await promoteAnotherCalendarAndRetry(id);\n    return;\n  }\n  throw e;\n}","preventionTips":["Before deleting, check is_default and transfer the default flag to another calendar.","Surfacing which calendar is default in the UI prevents surprise 400s.","Order bulk deletes so the default calendar is deleted last."],"tags":["calendar","default-calendar","http-400","open-webui"],"backgroundTag":null,"analyzedSha":"01f4282f1ffe0d6212f58d3afbeae21fffd0c4be","analyzedAt":"2026-08-14T18:25:22.715Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}