{"record":{"id":"6ce0291de13bca44","repo":"clockworklabs/SpacetimeDB","slug":"view-not-found-in-module-def","errorCode":null,"errorMessage":"view {} not found in module_def","messagePattern":"view (.+?) not found in module_def","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/wasm_common/module_host_actor.rs","lineNumber":1642,"sourceCode":"    owner_identity: Identity,\n) -> Result<Vec<CallViewParams>, anyhow::Error> {\n    let mut view_calls = Vec::new();\n\n    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(),","sourceCodeStart":1624,"sourceCodeEnd":1660,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/core/src/host/wasm_common/module_host_actor.rs#L1624-L1660","documentation":"Raised in collect_subscribed_view_calls while building the list of view calls used to refresh subscribed views after a mutation. The code iterates module_def.all_views_with_prefix() and then re-looks each view up by its joined canonical name via view_by_name_with_global_fn_ptr; the lookup failing means the module definition's own name-to-view index disagrees with its view list. This is an internal invariant violation inside ModuleDef, not a user input error.","triggerScenarios":"Any mutation that triggers subscribed-view refresh (e.g. SQL DML going through call_views_with_tx) when prefix.join(local_name) produces a name that view_by_name_with_global_fn_ptr cannot resolve - e.g. empty or colliding view local names after prefix joining, or a corrupted/hand-generated module definition.","commonSituations":"Custom or pre-release module builds; SDK and host version skew; essentially unreachable for modules built with the standard toolchain.","solutions":["Update to a matched SpacetimeDB host/SDK version pair and republish the module","Rebuild the module with the standard toolchain (spacetime build) so ModuleDef and its name index are generated consistently","Reproduce with a minimal module and file a bug - this path indicates an internal ModuleDef inconsistency"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Sanity-check ModuleDef name-index consistency before running mutations\nfor (prefix, _, view) in module_def.all_views_with_prefix() {\n    let name = prefix.join(view.name.clone());\n    if module_def.view_by_name_with_global_fn_ptr(&name).is_none() {\n        return Err(anyhow::anyhow!(\"ModuleDef name index inconsistent for view {name}; rebuild the module\"));\n    }\n}","typeGuard":null,"tryCatchPattern":"match collect_result {\n    Err(e) if e.to_string().contains(\"not found in module_def\") => {\n        // Internal invariant failure: rebuild/re-publish the module, then retry once\n    }\n    other => other,\n}","preventionTips":["Build modules only with the standard toolchain (spacetime build)","Keep host and SDK versions matched","Treat this error as a bug report trigger, not a runtime condition to handle"],"tags":["spacetimedb","views","module-def","internal-invariant"],"backgroundTag":"module-definition-inconsistency","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"}