clockworklabs/SpacetimeDB · error · anyhow::Error
view not found in database
Error message
view {} not found in database What it means
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.
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
Example fix
# before: database published from an older module without the view spacetime sql my_db "insert into t values (1)" # -> view my_module.my_view not found in database # after: republish so the view is registered spacetime publish my_db spacetime sql my_db "insert into t values (1)"
Defensive patterns
Strategy: validation
Validate before calling
// Before running DML that refreshes views, ensure every module view is registered
let missing: Vec<String> = module_def
.all_views_with_prefix()
.map(|(prefix, _, v)| prefix.join(v.name.clone()))
.filter(|name| tx.view_from_name(name).ok().flatten().is_none())
.collect();
if !missing.is_empty() {
return Err(anyhow::anyhow!("views not registered in database: {missing:?}; republish first"));
} Try / catch
match dml_result {
Err(e) if e.to_string().contains("not found in database") => {
// Trigger a republish / alert the operator, then retry the mutation
}
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Publishing module updates out of order; manually deleting st_view rows; pointing a host at the wrong database; renaming modules or views without republishing.
Related errors
- view does not have a backing table in database
- AddColumns: table ` ` not found in new module def
- AddConstraint: ` ` not found in new module def
- AddRowLevelSecurity: RLS
- AddSequence: ` ` not found in new module def
AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20).
Data as JSON: /api/errors/0819ab38faf579ee.
Report an issue: GitHub.
Appendix: source
Thrown at crates/core/src/host/wasm_common/module_host_actor.rs:1646
for (prefix, owning_def, view) in module_def.all_views_with_prefix() {
let ViewDef {
name: local_name,
is_anonymous,
product_type_ref,
..
} = view;
// Full namespaced canonical name: matches both the st_view registration
// (create_view / create_view_with_prefix) and `view_by_name_with_global_fn_ptr`.
let view_name = prefix.join(local_name.clone());
let (global_fn_ptr, _, _) = module_def
.view_by_name_with_global_fn_ptr(&view_name)
.ok_or_else(|| anyhow::anyhow!("view {} not found in module_def", view_name))?;
let st_view = tx
.view_from_name(&view_name)?
.ok_or_else(|| anyhow::anyhow!("view {} not found in database", view_name))?;
let view_id = st_view.view_id;
let table_id = st_view
.table_id
.ok_or_else(|| anyhow::anyhow!("view {} does not have a backing table in database", view_name))?;
let subs = tx.materialized_view_instances_for_view(view_id);
let view_typespace = Arc::new(owning_def.typespace().clone());
if *is_anonymous {
if subs.is_empty() {
continue;
}
view_calls.push(CallViewParams {
view_name: view_name.clone(),
view_id,
table_id,
fn_ptr: global_fn_ptr,
caller: owner_identity,View on GitHub (pinned to eddf9f5014)