clockworklabs/SpacetimeDB · error
table schema should validate for query builder codegen
Error message
table schema should validate for query builder codegen
What it means
Panic in SpacetimeDB's Unreal C++ query-builder code generation. For every table in the module, the generator constructs `TableSchema::from_module_def(module, table, (), 0)` and calls `.validated()`; if the table schema collects validation errors, the `expect` panics and codegen aborts. The invariant assumed is that any table that passed module building must also pass table-schema validation.
Source
Thrown at crates/codegen/src/unrealcpp.rs:3257
if !(constraints.has_indexed() || constraints.has_unique() || constraints.has_primary_key()) {
continue;
}
let col_idx = columns.iter().next().expect("singleton column").idx();
let (field_name, _) = &product_type.elements[col_idx];
singleton_indexed_fields.push(field_name.deref().to_case(Case::Pascal));
}
singleton_indexed_fields
};
for table in iter_tables(module, visibility) {
let product_type = module.typespace_for_generate()[table.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, table.product_type_ref));
let source_pascal = table.accessor_name.deref().to_case(Case::Pascal);
let schema = TableSchema::from_module_def(module, table, (), 0.into())
.validated()
.expect("table 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
- Build/validate the module first and read the real validation errors (`spacetime build`) instead of relying on the codegen panic message.
- Bisect your module: comment out recently added tables and re-run codegen until the failing table is identified, then fix its definition.
- Align versions: upgrade the `spacetime` CLI and the module's `spacetimedb-std` dependency to the same release.
- Report upstream if a table that builds cleanly still panics here — that is a codegen invariant break, not a user error.
Example fix
// before: table whose schema fails validation (e.g. indexed unique on unsupported type)
table Player { name: String #[primary_key], payload: Bytes #[index] }
// after: index a supported, comparable type
table Player { name: String #[primary_key], score: u64 #[index] } Defensive patterns
Strategy: validation
Validate before calling
for table in iter_tables(module, visibility) {
let schema = TableSchema::from_module_def(module, table, (), 0.into());
if !schema.validated() { /* surface errors, skip codegen */ }
} Prevention
- Validate table schemas before invoking binding generation.
- Treat 'builds but fails codegen validation' as an upstream bug: pin the working CLI version and report it.
- Keep table definitions to types documented as supported for C++ bindings.
When it happens
Trigger: Running `spacetime generate` for Unreal C++ bindings where a table definition fails `TableSchema` validation: invalid index/constraint definitions, unsupported column types, or a table auto-injected with a generated row type that the validator rejects. `iter_tables(module, visibility)` feeds each table, so any single bad table kills the whole run.
Common situations: Version skew between the module SDK used to build the module and the CLI generating bindings; introducing a table with a newly supported type that older codegen validators reject; corrupted or hand-modified module description files; constraint/index syntax that changed between releases.
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
- Failed to generate table due to validation errors
- view schema should validate for query builder codegen
- table should exist in the database for AddConstraint
- expected ModuleDef to contain key, but it does not
- `table_id` must not be `TableId::SENTINEL` in `{row_level_se
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/6874ce49c8c95ded.
Report an issue: GitHub.