clockworklabs/SpacetimeDB · error

view schema should validate for query builder codegen

Error message

view schema should validate for query builder codegen

What it means

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.

Source

Thrown at crates/codegen/src/unrealcpp.rs:3294

            cols_struct: format!("F{module_prefix}{source_pascal}Cols"),
            ix_cols_struct: format!("F{module_prefix}{source_pascal}IxCols"),
            fields,
            singleton_indexed_fields,
            source_name: table.name.deref().to_string(),
            source_pascal,
            can_be_lookup: !table.is_event,
        });
    }

    for view in iter_views(module) {
        let product_type = module.typespace_for_generate()[view.product_type_ref]
            .as_product()
            .expect("query builder source should be a product type");
        let row_struct = format!("F{}Type", type_ref_name(module_prefix, module, view.product_type_ref));
        let source_pascal = view.accessor_name.deref().to_case(Case::Pascal);
        let schema = TableSchema::from_view_def_for_codegen(module, view)
            .validated()
            .expect("view schema should validate for query builder codegen");

        let singleton_indexed_fields = singleton_indexed_fields_for_schema(&schema, product_type);

        let fields = product_type
            .elements
            .iter()
            .map(|(field_name, field_ty)| {
                (
                    field_name.deref().to_string(),
                    field_name.deref().to_case(Case::Pascal),
                    cpp_ty_fmt_with_module(module_prefix, module, field_ty, module_name).to_string(),
                    field_ty.clone(),
                )
            })
            .collect::<Vec<_>>();

        source_metas.push(QueryBuilderSourceMeta {
            row_struct,

View on GitHub (pinned to 6dee26c6ef)

Solutions

  1. Validate the module with `spacetime build` and address the reported view validation errors before generating bindings.
  2. Temporarily remove views from the module and regenerate to isolate the failing view; fix or simplify its definition.
  3. Match `spacetime` CLI and `spacetimedb-std` module SDK versions to the same release.
  4. File an issue with the module schema if a view that builds successfully still panics during query-builder codegen.

Example fix

// before: view derived from a table shape that fails schema validation
view HighScores { SELECT score FROM Player WHERE score > 1000 }

// after: project plain scalar columns that validate cleanly
view HighScores { SELECT name, score FROM Player WHERE score > 1000 }
Defensive patterns

Strategy: validation

Validate before calling

for view in iter_views(module) {
    let schema = TableSchema::from_view_def_for_codegen(module, view);
    if !schema.validated() { /* report and abort before query-builder codegen */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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