{"record":{"id":"930790122a83e074","repo":"twentyhq/twenty","slug":"failed-to-backfill-imageidentifierfieldmetadataid","errorCode":null,"errorMessage":"Failed to backfill imageIdentifierFieldMetadataId for workspace ${workspaceId}","messagePattern":"Failed to backfill imageIdentifierFieldMetadataId for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-22/2-22-workspace-command-1783959648000-backfill-company-person-image-identifier-field-metadata-id.command.ts","lineNumber":164,"sourceCode":"            objectMetadata: {\n              flatEntityToCreate: [],\n              flatEntityToDelete: [],\n              flatEntityToUpdate: flatObjectMetadataToUpdate,\n            },\n          },\n          workspaceId,\n          isSystemBuild: true,\n          applicationUniversalIdentifier:\n            twentyStandardFlatApplication.universalIdentifier,\n        },\n      );\n\n    if (validateAndBuildResult.status === 'fail') {\n      this.logger.error(\n        `Failed to backfill imageIdentifierFieldMetadataId for workspace ${workspaceId}:\\n${JSON.stringify(validateAndBuildResult, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to backfill imageIdentifierFieldMetadataId for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(\n      `Backfilled imageIdentifierFieldMetadataId on ${flatObjectMetadataToUpdate\n        .map((flatObjectMetadata) => flatObjectMetadata.nameSingular)\n        .join(', ')} for workspace ${workspaceId}`,\n    );\n  }\n}\n","sourceCodeStart":146,"sourceCodeEnd":176,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-22/2-22-workspace-command-1783959648000-backfill-company-person-image-identifier-field-metadata-id.command.ts#L146-L176","documentation":"Thrown by the 2.22 command that backfills imageIdentifierFieldMetadataUniversalIdentifier on company (domainName) and person (avatarFile) objects. After computing which objects need the update (unset or pointing at deprecated field), the command calls validateBuildAndRunWorkspaceMigration with objectMetadata update operations. If the pipeline fails, the result is logged to logger.error and the generic error is thrown.","triggerScenarios":"validateBuildAndRunWorkspaceMigration returns status 'fail' when updating objectMetadata rows to set imageIdentifierFieldMetadataUniversalIdentifier. Caused by: the referenced field universal identifier not existing as a FlatFieldMetadata in the workspace, the object not existing in workspace metadata, stale cache, or a DB error.","commonSituations":"The domainName or avatarFile field was deleted or never created on the workspace; workspace cache has stale flatFieldMetadataMaps that do not reflect the actual DB state; a prior upgrade partially modified the object metadata.","solutions":["Read the logger.error output for JSON.stringify(validateAndBuildResult) containing the specific failure report","Flush flatObjectMetadataMaps and flatFieldMetadataMaps from workspace cache, then retry","Verify the target fields exist: check flatFieldMetadataMaps for domainName (company) and avatarFile (person) universal identifiers","Run with --dryRun to inspect the planned updates"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running, verify the target fields exist in the workspace cache\nconst { flatFieldMetadataMaps, flatObjectMetadataMaps } =\n  await workspaceCacheService.getOrRecompute(workspaceId, [\n    'flatFieldMetadataMaps',\n    'flatObjectMetadataMaps',\n  ]);\n\nconst hasDomainName = isDefined(\n  flatFieldMetadataMaps.byUniversalIdentifier[\n    STANDARD_OBJECTS.company.fields.domainName.universalIdentifier\n  ]\n);\n\nconst hasAvatarFile = isDefined(\n  flatFieldMetadataMaps.byUniversalIdentifier[\n    STANDARD_OBJECTS.person.fields.avatarFile.universalIdentifier\n  ]\n);\n\nif (!hasDomainName && !hasAvatarFile) {\n  console.log('No target fields exist — nothing to backfill');\n}","typeGuard":null,"tryCatchPattern":"// Retry after flushing cache\ntry {\n  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n} catch (error) {\n  if (error.message.includes('Failed to backfill imageIdentifierFieldMetadataId')) {\n    await workspaceCacheService.flush(workspaceId, ['flatObjectMetadataMaps', 'flatFieldMetadataMaps']);\n    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n  } else {\n    throw error;\n  }\n}","preventionTips":["Run with --dryRun first — the command already skips objects/fields that don't exist","Flush flatObjectMetadataMaps and flatFieldMetadataMaps before retrying","Parse the logger.error JSON for the specific objectMetadata validation failure","Ensure no concurrent workspace modifications during the upgrade"],"tags":["metadata","upgrade-command","workspace-migration","validate-build-run","object-metadata","image-identifier"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}