{"record":{"id":"d3b08e2e0f636c38","repo":"passbolt/passbolt_api","slug":"the-resource-metadata-key-data-could-not-be-updated","errorCode":null,"errorMessage":"The resource metadata key data could not be updated.","messagePattern":"The resource metadata key data could not be updated\\.","errorType":"validation","errorClass":"CustomValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/RotateKey/MetadataRotateKeyResourcesUpdateService.php","lineNumber":83,"sourceCode":"                    'username' => true,\n                    'uri' => true,\n                    'description' => true,\n                    'resource_type_id' => true, // required for upgrade\n                    'metadata_key_id' => true,\n                    'metadata_key_type' => true,\n                    'metadata' => true,\n                    'modified' => true,\n                    'modified_by' => true,\n                ],\n                'validate' => 'v5',\n            ]);\n            foreach (MetadataResourceDto::V4_META_PROPS as $prop) {\n                $entity->set($prop, null);\n            }\n\n            if ($entity->getErrors()) {\n                $errors = [$i => $entity->getErrors()];\n                throw new CustomValidationException(__('The resource metadata key data could not be updated.'), $errors); // phpcs:ignore\n            }\n\n            $entities[$i] = $entity;\n        }\n\n        try {\n            $resourcesTable->saveManyOrFail($entities, [\n                IsV4ToV5UpgradeAllowedRule::SKIP_RULE_OPTION => true,\n                IsSharedMetadataKeyUniqueActiveRule::SKIP_RULE_OPTION => false,\n            ]);\n        } catch (PersistenceFailedException $exception) { // @phpstan-ignore-line\n            $this->handleSaveManyValidationException(\n                $exception,\n                $entities,\n                __('The resource metadata key data could not be updated.')\n            );\n        } catch (Exception $exception) {\n            throw new InternalErrorException(","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/RotateKey/MetadataRotateKeyResourcesUpdateService.php#L65-L101","documentation":"A CustomValidationException thrown inside MetadataRotateKeyResourcesUpdateService::updateData before saving. After clearing the v4 metadata properties on a resource entity, the entity still reports validation errors ($entity->getErrors()), so the rotation for that resource is aborted with the message 'The resource metadata key data could not be updated.' and the per-entity error set as validation details.","triggerScenarios":"Rotating a metadata key on resources where, after unsetting the V4_META_PROPS fields, the resource entity fails buildRules/validation — e.g. invalid metadata object, missing required v5 metadata fields, or a rule violation on the resource row being transformed.","commonSituations":"Legacy v4 resources with corrupt or hand-edited metadata payloads; partially migrated databases where resource_types/metadata columns are inconsistent; running rotation right after a failed earlier migration pass.","solutions":["Read the `errors` payload attached to the exception response to identify the failing resource index and field","Sanitize/repair the offending resource rows (fix metadata JSON, resourceTypeId, or required fields) and re-run rotation","Ensure resource_type metadata migration completed before rotating keys","Add/refresh validation rules so invalid legacy rows are fixed or skipped with explicit reporting"],"exampleFix":"// before\nif ($entity->getErrors()) {\n    throw new CustomValidationException(__('The resource metadata key data could not be updated.'), [$i => $entity->getErrors()]);\n}\n// after (surface which entity and fields failed in logs too)\nif ($entity->getErrors()) {\n    Log::error('Resource rotation validation failed', ['index' => $i, 'errors' => $entity->getErrors()]);\n    throw new CustomValidationException(__('The resource metadata key data could not be updated.'), [$i => $entity->getErrors()]);\n}","handlingStrategy":"validation","validationCode":"use Cake\\Validation\\Validation;\nforeach ($resources as $r) {\n    if (empty($r['id']) || !Validation::uuid($r['id'])) { continue; }\n    $entity = $resourcesTable->get($r['id']);\n    $entity->set('metadata', $newMetadata);\n    $errors = $entity->getErrors();\n    if ($errors) { /* repair rows before invoking rotation */ }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $service->updateData(...);\n} catch (CustomValidationException $e) {\n    $errors = $e->getErrors(); // map of index => field errors; fix listed resources\n}","preventionTips":["Fix corrupt legacy resource metadata before rotation","Ensure v4->v5 resource type migration finished first","Validate entities locally with the same table rules before batch save","Keep resource_types rows untouched by hand"],"tags":["cakephp","metadata-rotation","resources","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}