{"record":{"id":"1c39c34976c119ff","repo":"LemmyNet/lemmy","slug":"err-getting-local-site-e","errorCode":null,"errorMessage":"err getting local site: {e:?}","messagePattern":"err getting local site: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/db_views/site/src/impls.rs","lineNumber":77,"sourceCode":"    CACHE\n      .try_get_with((), async move {\n        let conn = &mut get_conn(pool).await?;\n        let local_site = site::table\n          .inner_join(local_site::table)\n          .inner_join(instance::table)\n          .inner_join(\n            local_site_rate_limit::table\n              .on(local_site::id.eq(local_site_rate_limit::local_site_id)),\n          )\n          .select(Self::as_select())\n          .first(conn)\n          .await\n          .optional()?\n          .ok_or(LemmyErrorType::LocalSiteNotSetup)?;\n        Ok(local_site)\n      })\n      .await\n      .map_err(|e: Arc<LemmyError>| anyhow::anyhow!(\"err getting local site: {e:?}\").into())\n  }\n\n  /// A special site bot user, solely made for following non-local communities for\n  /// multi-communities.\n  pub async fn read_system_account(pool: &mut DbPool<'_>) -> LemmyResult<Person> {\n    let site_view = SiteView::read_local(pool).await?;\n    Person::read(pool, site_view.local_site.system_account).await\n  }\n}\n\npub async fn user_backup_list_to_user_settings_backup(\n  local_user_view: LocalUserView,\n  pool: &mut DbPool<'_>,\n) -> LemmyResult<UserSettingsBackup> {\n  let lists = LocalUser::export_backup(pool, local_user_view.person.id).await?;\n  let blocking_keywords = LocalUserKeywordBlock::read(pool, local_user_view.local_user.id).await?;\n  let discussion_languages = LocalUserLanguage::read(pool, local_user_view.local_user.id).await?;\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/LemmyNet/lemmy/blob/439734dd638a2c06a2f907beab7dcf4646e88f86/crates/db_views/site/src/impls.rs#L59-L95","documentation":"SiteView::read_local queries the local_site row and returns LocalSiteNotSetup when none exists; any other DB failure is wrapped into this anyhow error. It means the instance's local site record could not be loaded.","triggerScenarios":"Calling read_local on an instance whose local_site row is absent (fresh/undone setup) or where the underlying query fails — connection problems, wrong DB, migrations not applied.","commonSituations":"Starting federation/tasks before completing Lemmy setup (local site never created); pointing at the wrong database; failed or partial migrations; DB connectivity loss at boot.","solutions":["Complete instance setup so the local_site row exists (finish the Lemmy bootstrap/admin setup)","Verify DB connection settings point at the correct, migrated database","Run pending migrations and restart","Inspect the inner debug error to distinguish not-setup from a connection failure"],"exampleFix":"// before\nlet site = SiteView::read_local(pool).await?; // panics-equivalent when local_site absent\n// after\nif let Err(e) = SiteView::read_local(pool).await {\n  eprintln!(\"local site not available yet, deferring startup: {e}\");\n  // wait/retry until setup completes\n}","handlingStrategy":"retry","validationCode":"let exists: Option<i32> = sqlx/diesel query \"SELECT 1 FROM local_site\" ...optional().await?;\nif exists.is_none() {\n  // defer startup until instance setup is complete\n}","typeGuard":null,"tryCatchPattern":"match SiteView::read_local(pool).await {\n  Ok(site) => start_with(site),\n  Err(e) => { warn!(\"local site not ready: {e}\"); wait_and_retry(); }\n}","preventionTips":["Finish instance setup before enabling federation workers","Confirm DB hostname/database name in config points to the migrated DB","Run migrations on every deploy","Alert on LocalSiteNotSetup at boot"],"tags":["database","site-config","lemmy","setup"],"backgroundTag":"missing-required-config","analyzedSha":"439734dd638a2c06a2f907beab7dcf4646e88f86","analyzedAt":"2026-09-06T11:28:35.035Z","contentChangedAt":"2026-09-06T11:28:35.035Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}