passbolt/passbolt_api · error · CustomValidationException

The resource metadata key data could not be updated.

Error message

The resource metadata key data could not be updated.

What it means

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.

Solutions

  1. Read the `errors` payload attached to the exception response to identify the failing resource index and field
  2. Sanitize/repair the offending resource rows (fix metadata JSON, resourceTypeId, or required fields) and re-run rotation
  3. Ensure resource_type metadata migration completed before rotating keys
  4. Add/refresh validation rules so invalid legacy rows are fixed or skipped with explicit reporting

Example fix

// before
if ($entity->getErrors()) {
    throw new CustomValidationException(__('The resource metadata key data could not be updated.'), [$i => $entity->getErrors()]);
}
// after (surface which entity and fields failed in logs too)
if ($entity->getErrors()) {
    Log::error('Resource rotation validation failed', ['index' => $i, 'errors' => $entity->getErrors()]);
    throw new CustomValidationException(__('The resource metadata key data could not be updated.'), [$i => $entity->getErrors()]);
}
Defensive patterns

Strategy: validation

Validate before calling

use Cake\Validation\Validation;
foreach ($resources as $r) {
    if (empty($r['id']) || !Validation::uuid($r['id'])) { continue; }
    $entity = $resourcesTable->get($r['id']);
    $entity->set('metadata', $newMetadata);
    $errors = $entity->getErrors();
    if ($errors) { /* repair rows before invoking rotation */ }
}

Try / catch

try {
    $service->updateData(...);
} catch (CustomValidationException $e) {
    $errors = $e->getErrors(); // map of index => field errors; fix listed resources
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/d3b08e2e0f636c38. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/Metadata/src/Service/RotateKey/MetadataRotateKeyResourcesUpdateService.php:83

                    'username' => true,
                    'uri' => true,
                    'description' => true,
                    'resource_type_id' => true, // required for upgrade
                    'metadata_key_id' => true,
                    'metadata_key_type' => true,
                    'metadata' => true,
                    'modified' => true,
                    'modified_by' => true,
                ],
                'validate' => 'v5',
            ]);
            foreach (MetadataResourceDto::V4_META_PROPS as $prop) {
                $entity->set($prop, null);
            }

            if ($entity->getErrors()) {
                $errors = [$i => $entity->getErrors()];
                throw new CustomValidationException(__('The resource metadata key data could not be updated.'), $errors); // phpcs:ignore
            }

            $entities[$i] = $entity;
        }

        try {
            $resourcesTable->saveManyOrFail($entities, [
                IsV4ToV5UpgradeAllowedRule::SKIP_RULE_OPTION => true,
                IsSharedMetadataKeyUniqueActiveRule::SKIP_RULE_OPTION => false,
            ]);
        } catch (PersistenceFailedException $exception) { // @phpstan-ignore-line
            $this->handleSaveManyValidationException(
                $exception,
                $entities,
                __('The resource metadata key data could not be updated.')
            );
        } catch (Exception $exception) {
            throw new InternalErrorException(

View on GitHub (pinned to 31c1bbc10f)