{"record":{"id":"90b2f38753bbb2a2","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-metadata-key-data-for-the-entity-with","errorCode":null,"errorMessage":"Could not validate the metadata key data for the entity with ID: {0}.","messagePattern":"Could not validate the metadata key data for the entity with ID: (.+?)\\.","errorType":"validation","errorClass":"CustomValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php","lineNumber":90,"sourceCode":"        $errors = [];\n        foreach ($requestData as $i => $entity) {\n            $entityId = $entity['id'];\n            if (!array_key_exists($entityId, $this->entities)) {\n                throw new NotFoundException(__('Entity {0} not found.', $entityId));\n            }\n\n            /** @var \\Passbolt\\Metadata\\Model\\Entity\\MetadataKey|null $metadataKey */\n            $metadataKey = $this->entities[$entityId]['metadata_key'] ?? null;\n            if (!is_null($metadataKey)) {\n                $metadataKey = $metadataKey->toArray();\n            }\n            $entity['metadata_key'] = $metadataKey;\n            $entity = $this->setMetadataKeyIdIfNotDefinedAndEntityIsPersonal($entity);\n\n            $form = $this->getForm();\n            if (!$form->execute($entity)) {\n                $errors[$i] = $form->getErrors();\n                throw new CustomValidationException(__('Could not validate the metadata key data for the entity with ID: {0}.', $entityId), $errors); // phpcs:ignore;\n            }\n            $data[$i] = $form->getData();\n        }\n\n        return $data;\n    }\n\n    /**\n     * Returns fetched entities from the DB.\n     *\n     * @return array\n     */\n    public function getEntities(): array\n    {\n        return $this->entities;\n    }\n\n    /**","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php#L72-L108","documentation":"For each valid batch entry, validateMany executes the plugin's update form ($form->execute($entity)). When the form fails validation, it collects $form->getErrors() and throws CustomValidationException with this message, attaching the per-entity error details. It signals the metadata key data (metadata_key_id / metadata_key_type combination) did not pass form rules.","triggerScenarios":"Batch metadata updates where an entity's metadata_key_id/metadata_key_type pair is invalid — e.g. referencing a nonexistent or deleted metadata key, mismatched key type, missing fields required by the form, or a personal-key rule violation caught by setMetadataKeyIdIfNotDefinedAndEntityIsPersonal.","commonSituations":"Migrating resources to a metadata key that was revoked/deleted; sending metadata_key_type 'shared_key' with a user key ID or vice versa; automation omitting metadata_key_id expecting the server to infer it; form schema changes after a passbolt upgrade.","solutions":["Inspect the CustomValidationException's errors payload ($form->getErrors()) to see the exact failing field and rule, then fix that field.","Verify the metadata_key_id references an existing, non-deleted metadata key (GET /metadata/keys.json).","Ensure metadata_key_type matches the key ('shared_key' or 'user_key') and is consistent with metadata_key_id.","Enable debug logging to see per-entity validation errors during the batch, and resubmit corrected entries."],"exampleFix":"// before\n{\"id\": \"<uuid>\", \"metadata\": \"<encrypted>\", \"metadata_key_id\": \"nonexistent-key-uuid\", \"metadata_key_type\": \"shared_key\"}\n\n// after (use a valid key id from GET /metadata/keys.json)\n{\"id\": \"<uuid>\", \"metadata\": \"<encrypted>\", \"metadata_key_id\": \"<valid-active-key-uuid>\", \"metadata_key_type\": \"shared_key\"}","handlingStrategy":"try-catch","validationCode":"$key = $metadataKeysTable->find()->where(['id' => $metadataKeyId, 'deleted' => false])->first();\nif (!$key) {\n    throw new InvalidArgumentException('metadata_key_id must reference an existing, non-deleted key');\n}\nif (!in_array($metadataKeyType, [MetadataKey::TYPE_SHARED_KEY, MetadataKey::TYPE_USER_KEY], true)) {\n    throw new InvalidArgumentException('Invalid metadata_key_type');\n}","typeGuard":"function isValidMetadataKeyRef(?string $keyId, ?string $keyType): bool {\n    return $keyId !== null && $keyType !== null\n        && in_array($keyType, ['shared_key', 'user_key'], true);\n}","tryCatchPattern":"try {\n    $data = $service->validateMany($requestData);\n} catch (CustomValidationException $e) {\n    $errors = $e->getErrors(); // per-entity form errors; fix fields then resubmit\n}","preventionTips":["Inspect getErrors() from CustomValidationException to pinpoint the failing rule","Reference only active (non-deleted) metadata keys in batch updates","Keep metadata_key_type consistent with the referenced key","Validate one entity through the form before running the full batch"],"tags":["passbolt","batch-update","form-validation","metadata-key","custom-validation-exception"],"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"}