{"record":{"id":"7ce2cfe0163b6705","repo":"elsa-workflows/elsa-core","slug":"physicalized-index-index-name-references-undeclared-field","errorCode":null,"errorMessage":"Physicalized index '{index.Name}' references undeclared field '{missingField}' on storage unit '{storageUnit.Name}'.","messagePattern":"Physicalized index '(.+?)' references undeclared field '(.+?)' on storage unit '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext/Physicalization/PhysicalizationPolicyValidator.cs","lineNumber":21,"sourceCode":"namespace Elsa.Persistence.VNext.Physicalization;\n\npublic static class PhysicalizationPolicyValidator\n{\n    public static PersistenceStorageUnit GetStorageUnit(PersistenceSchema schema, StoragePhysicalizationPolicy policy)\n    {\n        var storageUnit = schema.StorageUnits.SingleOrDefault(x => x.Name == policy.StorageUnit);\n\n        if (storageUnit == null)\n            throw new InvalidOperationException($\"Storage unit '{policy.StorageUnit}' was not declared by schema '{schema.Name}'.\");\n\n        var fields = storageUnit.Fields.Select(x => x.Name).ToHashSet(StringComparer.Ordinal);\n\n        foreach (var index in policy.Indexes)\n        {\n            var missingField = index.Fields.FirstOrDefault(field => !fields.Contains(field));\n\n            if (missingField != null)\n                throw new InvalidOperationException($\"Physicalized index '{index.Name}' references undeclared field '{missingField}' on storage unit '{storageUnit.Name}'.\");\n        }\n\n        return storageUnit;\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":27,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext/Physicalization/PhysicalizationPolicyValidator.cs#L3-L27","documentation":"After resolving the storage unit, GetStorageUnit validates every index in the physicalization policy: each index field must exist on the declared storage unit. This error means an index named by the policy references a field the storage unit never declared, so physicalizing it would produce an index over a nonexistent column.","triggerScenarios":"Adding an index to StoragePhysicalizationPolicy.Indexes whose Fields include a name not among storageUnit.Fields — typically after renaming or removing a field, or defining indexes against a unit's old shape.","commonSituations":"Schema field renamed while physicalization policy still references the old field name; index copied from another storage unit's policy; typo in field name.","solutions":["Remove or correct the index field in policy.Indexes to reference a field declared on the storage unit.","Add the missing field to the storage unit definition if it is genuinely needed.","Sync the policy definition with the current schema after field renames."],"exampleFix":"// before\npolicy.Indexes.Add(new IndexPhysicalizationPolicy { Name = \"IX_Status\", Fields = [\"Staus\"] });\n// after\npolicy.Indexes.Add(new IndexPhysicalizationPolicy { Name = \"IX_Status\", Fields = [\"Status\"] });","handlingStrategy":"validation","validationCode":"var unit = schema.StorageUnits.Single(u => u.Name == policy.StorageUnit);\nvar fieldSet = unit.Fields.Select(f => f.Name).ToHashSet(StringComparer.Ordinal);\nvar bad = policy.Indexes.SelectMany(i => i.Fields).FirstOrDefault(f => !fieldSet.Contains(f));\nif (bad != null) throw new InvalidOperationException($\"Index field '{bad}' is not declared on '{unit.Name}'.\");","typeGuard":null,"tryCatchPattern":"try { GetStorageUnit(schema, policy); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"references undeclared field\")) { /* correct index fields */ }","preventionTips":["Build policy indexes from the storage unit's declared field names.","Run schema/policy consistency checks in CI.","Grep for stale field names after renames."],"tags":["physicalization","index","schema-validation","policy"],"backgroundTag":"schema-validation-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}