clockworklabs/SpacetimeDB · error · anyhow::Error

view does not have a backing table in database

Error message

view {} does not have a backing table in database

What it means

The st_view row for the view exists but its table_id column is NULL, so there is no backing table to write materialized rows into. collect_subscribed_view_calls needs table_id to construct the refresh call, so view refresh aborts. A view row without a backing table means view creation was interrupted or the metadata was written in a partially initialized state.

Solutions

  1. Republish the module so view creation runs again and assigns the backing table
  2. If it persists, change the view set (or drop/recreate the view) to force clean metadata, then republish
  3. Check server logs for a failed or interrupted publish around the time the view was created
Defensive patterns

Strategy: validation

Validate before calling

// Ensure each registered view has a backing table before mutations
for name in module_view_names {
    if let Some(st_view) = tx.view_from_name(&name).ok().flatten() {
        if st_view.table_id.is_none() {
            return Err(anyhow::anyhow!("view {name} lacks a backing table; republish to repair"));
        }
    }
}

Try / catch

match dml_result {
    Err(e) if e.to_string().contains("does not have a backing table") => {
        // Republish the module to rebuild view metadata, then retry
    }
    other => other,
}

Prevention

When it happens

Trigger: A publish or create_view that failed between inserting the st_view row and allocating its backing table; concurrent publishes racing on the same view name; direct manipulation of st_view rows.

Common situations: Interrupted spacetime publish (Ctrl-C, node restart mid-publish); older server versions with non-atomic view creation.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20). Data as JSON: /api/errors/5932a1039d259ed6. Report an issue: GitHub.

Appendix: source

Thrown at crates/core/src/host/wasm_common/module_host_actor.rs:1651

            ..
        } = 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,
                sender: None,
                args: ArgsTuple::nullary(),
                row_type: *product_type_ref,
                timestamp: Timestamp::now(),
                view_typespace: view_typespace.clone(),

View on GitHub (pinned to eddf9f5014)