{"record":{"id":"e2b13847f382d5e6","repo":"clockworklabs/SpacetimeDB","slug":"view-schema-should-validate-for-query-builder-code","errorCode":null,"errorMessage":"view schema should validate for query builder codegen","messagePattern":"view schema should validate for query builder codegen","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/src/unrealcpp.rs","lineNumber":3294,"sourceCode":"            cols_struct: format!(\"F{module_prefix}{source_pascal}Cols\"),\n            ix_cols_struct: format!(\"F{module_prefix}{source_pascal}IxCols\"),\n            fields,\n            singleton_indexed_fields,\n            source_name: table.name.deref().to_string(),\n            source_pascal,\n            can_be_lookup: !table.is_event,\n        });\n    }\n\n    for view in iter_views(module) {\n        let product_type = module.typespace_for_generate()[view.product_type_ref]\n            .as_product()\n            .expect(\"query builder source should be a product type\");\n        let row_struct = format!(\"F{}Type\", type_ref_name(module_prefix, module, view.product_type_ref));\n        let source_pascal = view.accessor_name.deref().to_case(Case::Pascal);\n        let schema = TableSchema::from_view_def_for_codegen(module, view)\n            .validated()\n            .expect(\"view schema should validate for query builder codegen\");\n\n        let singleton_indexed_fields = singleton_indexed_fields_for_schema(&schema, product_type);\n\n        let fields = product_type\n            .elements\n            .iter()\n            .map(|(field_name, field_ty)| {\n                (\n                    field_name.deref().to_string(),\n                    field_name.deref().to_case(Case::Pascal),\n                    cpp_ty_fmt_with_module(module_prefix, module, field_ty, module_name).to_string(),\n                    field_ty.clone(),\n                )\n            })\n            .collect::<Vec<_>>();\n\n        source_metas.push(QueryBuilderSourceMeta {\n            row_struct,","sourceCodeStart":3276,"sourceCodeEnd":3312,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/codegen/src/unrealcpp.rs#L3276-L3312","documentation":"Panic in SpacetimeDB's Unreal C++ query-builder code generation, mirroring error 601 but for views. For each `view` in the module, `TableSchema::from_view_def_for_codegen(module, view).validated()` must return a valid schema; otherwise `expect(\"view schema should validate for query builder codegen\")` panics. It signals that a view definition passed module building but fails downstream schema validation.","triggerScenarios":"Running `spacetime generate` for Unreal C++ bindings on a module containing a view whose derived schema does not validate — e.g. a view over a table with incompatible index definitions, or a projection whose element types the validator rejects. `iter_views(module)` iterates all views, so one bad view aborts generation for the whole module.","commonSituations":"Adding new views after upgrading the SpacetimeDB SDK; views that worked under older validation rules; modules with complex projections or filters that the codegen schema layer cannot represent; mismatched CLI/SDK versions.","solutions":["Validate the module with `spacetime build` and address the reported view validation errors before generating bindings.","Temporarily remove views from the module and regenerate to isolate the failing view; fix or simplify its definition.","Match `spacetime` CLI and `spacetimedb-std` module SDK versions to the same release.","File an issue with the module schema if a view that builds successfully still panics during query-builder codegen."],"exampleFix":"// before: view derived from a table shape that fails schema validation\nview HighScores { SELECT score FROM Player WHERE score > 1000 }\n\n// after: project plain scalar columns that validate cleanly\nview HighScores { SELECT name, score FROM Player WHERE score > 1000 }","handlingStrategy":"validation","validationCode":"for view in iter_views(module) {\n    let schema = TableSchema::from_view_def_for_codegen(module, view);\n    if !schema.validated() { /* report and abort before query-builder codegen */ }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate views before generate, not after the panic.","Test view changes with generate in CI for every module change.","Avoid projecting types the target binding language documents as unsupported."],"tags":["rust","spacetimedb","codegen","query-builder","unreal","views","validation","panic"],"backgroundTag":"schema-validation-failed","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}