{"record":{"id":"51311199b395e165","repo":"twentyhq/twenty","slug":"multiple-validation-errors-occurred-while-normaliz","errorCode":null,"errorMessage":"Multiple validation errors occurred while normalizing composite field defaults","messagePattern":"Multiple validation errors occurred while normalizing composite field defaults","errorType":"exception","errorClass":"WorkspaceMigrationBuilderException","httpStatus":null,"severity":"critical","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-5/2-5-workspace-command-1778000001000-normalize-composite-field-defaults.command.ts","lineNumber":190,"sourceCode":"\n      const validateAndBuildResult =\n        await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(\n          {\n            allFlatEntityOperationByMetadataName: {\n              fieldMetadata: {\n                flatEntityToCreate: [],\n                flatEntityToDelete: [],\n                flatEntityToUpdate: flatFieldMetadatasToUpdate,\n              },\n            },\n            workspaceId,\n            isSystemBuild: true,\n            applicationUniversalIdentifier,\n          },\n        );\n\n      if (validateAndBuildResult.status === 'fail') {\n        throw new WorkspaceMigrationBuilderException(\n          validateAndBuildResult,\n          'Multiple validation errors occurred while normalizing composite field defaults',\n        );\n      }\n\n      for (const field of fields) {\n        this.logger.log(\n          `Normalized defaultValue for composite field \"${field.name}\" (${field.id}) in workspace ${workspaceId}`,\n        );\n      }\n    }\n\n    await this.workspaceCacheService.invalidateAndRecompute(workspaceId, [\n      'flatFieldMetadataMaps',\n    ]);\n\n    for (const { tableName, columnName } of backfillTargets) {\n      await dataSource.query(","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-5/2-5-workspace-command-1778000001000-normalize-composite-field-defaults.command.ts#L172-L208","documentation":"Thrown by the 2.5 command that normalizes composite field default values (replaces empty-string composite defaults with NULL). Unlike the others, it throws a WorkspaceMigrationBuilderException carrying the failed result and this message. It groups affected composite fields by application and submits each batch through validateBuildAndRunLegacyWorkspaceMigration (isSystemBuild: true); the first batch whose status === 'fail' raises the exception. The exception's failedWorkspaceMigrationBuildResult.report details the failing field(s).","triggerScenarios":"A composite field's normalized defaultValue shape fails the field-metadata validator (unknown property, wrong type per composite type definition); the field references an object that no longer exists; a compositeTypeDefinitions entry for the field's type is malformed so nullifyEmptyCompositeDefaultValue produced an invalid shape.","commonSituations":"Workspaces with custom composite fields whose defaultValue was set to non-standard shapes by older app code; cross-version upgrade where the composite type definition changed between releases; manual DB edits that left empty strings in composite default JSON.","solutions":["Catch WorkspaceMigrationBuilderException and read exception.failedWorkspaceMigrationBuildResult.report — it lists the failing field universalIdentifier(s) and error codes.","For each flagged field, inspect its stored defaultValue JSON and correct it to match the composite type definition (or set it to NULL).","Re-run the 2.5 command for the workspace; the field will be skipped once its default is valid."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Per composite field, validate the normalized shape before submitting:\nconst normalized = nullifyEmptyCompositeDefaultValue({ defaultValue: field.defaultValue, fieldType: field.type });\nfor (const property of compositeType.properties) {\n  if (normalized && !(property.name in normalized)) { /* repair field.defaultValue first */ }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await command.runOnWorkspace({ workspaceId, options });\n} catch (e) {\n  if (e instanceof WorkspaceMigrationBuilderException) {\n    const report = e.failedWorkspaceMigrationBuildResult.report;\n    logger.error({ workspaceId, report }, 'composite default normalize failed');\n  } else throw e;\n}","preventionTips":["Avoid setting non-standard defaultValue shapes on composite fields in app code.","On failure, read exception.failedWorkspaceMigrationBuildResult.report to find the offending field.","Set a malformed field's defaultValue to NULL before retrying."],"tags":["migration","upgrade-command","validate-and-build","workspace","composite-field","default-value","workspace-migration-builder-exception"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}