{"record":{"id":"0819ab38faf579ee","repo":"clockworklabs/SpacetimeDB","slug":"view-not-found-in-database","errorCode":null,"errorMessage":"view {} not found in database","messagePattern":"view (.+?) not found in database","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/wasm_common/module_host_actor.rs","lineNumber":1646,"sourceCode":"    for (prefix, owning_def, view) in module_def.all_views_with_prefix() {\n        let ViewDef {\n            name: local_name,\n            is_anonymous,\n            product_type_ref,\n            ..\n        } = view;\n\n        // Full namespaced canonical name: matches both the st_view registration\n        // (create_view / create_view_with_prefix) and `view_by_name_with_global_fn_ptr`.\n        let view_name = prefix.join(local_name.clone());\n\n        let (global_fn_ptr, _, _) = module_def\n            .view_by_name_with_global_fn_ptr(&view_name)\n            .ok_or_else(|| anyhow::anyhow!(\"view {} not found in module_def\", view_name))?;\n\n        let st_view = tx\n            .view_from_name(&view_name)?\n            .ok_or_else(|| anyhow::anyhow!(\"view {} not found in database\", view_name))?;\n\n        let view_id = st_view.view_id;\n        let table_id = st_view\n            .table_id\n            .ok_or_else(|| anyhow::anyhow!(\"view {} does not have a backing table in database\", view_name))?;\n        let subs = tx.materialized_view_instances_for_view(view_id);\n        let view_typespace = Arc::new(owning_def.typespace().clone());\n\n        if *is_anonymous {\n            if subs.is_empty() {\n                continue;\n            }\n            view_calls.push(CallViewParams {\n                view_name: view_name.clone(),\n                view_id,\n                table_id,\n                fn_ptr: global_fn_ptr,\n                caller: owner_identity,","sourceCodeStart":1628,"sourceCodeEnd":1664,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/core/src/host/wasm_common/module_host_actor.rs#L1628-L1664","documentation":"In collect_subscribed_view_calls, the module definition declares a view but tx.view_from_name finds no st_view row for its canonical namespaced name (prefix joined with the local name). The database's view registry, populated at publish time via create_view/create_view_with_prefix, is out of sync with the module: the module knows the view, the database does not.","triggerScenarios":"Running a mutation that refreshes subscribed views against a database published from an older module version that lacked the view; a failed or partial publish that skipped view registration; a module or namespace rename that changed the canonical name so it no longer matches the registered st_view name.","commonSituations":"Publishing module updates out of order; manually deleting st_view rows; pointing a host at the wrong database; renaming modules or views without republishing.","solutions":["Republish the module (spacetime publish) so every module view is (re)registered in st_view","Confirm the module/namespace prefix used at publish matches the module definition, since view_name is prefix.join(local_name)","Never edit st_* system tables directly; restore consistency by republishing"],"exampleFix":"# before: database published from an older module without the view\nspacetime sql my_db \"insert into t values (1)\"\n# -> view my_module.my_view not found in database\n\n# after: republish so the view is registered\nspacetime publish my_db\nspacetime sql my_db \"insert into t values (1)\"","handlingStrategy":"validation","validationCode":"// Before running DML that refreshes views, ensure every module view is registered\nlet missing: Vec<String> = module_def\n    .all_views_with_prefix()\n    .map(|(prefix, _, v)| prefix.join(v.name.clone()))\n    .filter(|name| tx.view_from_name(name).ok().flatten().is_none())\n    .collect();\nif !missing.is_empty() {\n    return Err(anyhow::anyhow!(\"views not registered in database: {missing:?}; republish first\"));\n}","typeGuard":null,"tryCatchPattern":"match dml_result {\n    Err(e) if e.to_string().contains(\"not found in database\") => {\n        // Trigger a republish / alert the operator, then retry the mutation\n    }\n    other => other,\n}","preventionTips":["Republish the module whenever views or namespaces change","Never delete or mutate st_view rows directly","Verify publish succeeded (exit code + logs) before sending traffic"],"tags":["spacetimedb","views","database-metadata","publish"],"backgroundTag":"view-not-registered","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}