passbolt/passbolt_api · error · BadRequestException

The resource type can not be deleted as resources of this…

Error message

The resource type can not be deleted as resources of this type still exist.

What it means

Safety check in ResourceTypesDeleteService::delete(): a resource type cannot be soft-deleted while resources of that type still exist. Fires when the resources table reports a non-zero count of resources referencing the type, preventing orphaned resources; admins must migrate or delete those resources first. (Related guards block deleting the last resource type of the default version or the last available type.)

Solutions

  1. Delete or move resources of this type first
  2. Bulk-edit resources to another type before retrying
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at plugins/PassboltCe/ResourceTypes/src/Service/ResourceTypesDeleteService.php:80

        }

        $highlander = new ResourceTypesIsTheLastOneCheckService();
        if ($highlander->isLastOfTheDefaultVersion($resourceType)) {
            throw new BadRequestException(__('You cannot delete the last resource type of the default version.'));
        }
        if ($highlander->isTheOnlyOne($resourceType)) {
            throw new BadRequestException(__('You cannot delete the last resource type available.'));
        }

        /** @var \App\Model\Table\ResourcesTable $resourcesTable */
        $resourcesTable = $this->fetchTable('Resources');
        $count = $resourcesTable->find()->where([
            'resource_type_id' => $resourceTypeId,
            'deleted' => false,
        ])->all()->count();
        if ($count !== 0) {
            $msg = __('The resource type can not be deleted as resources of this type still exist.');
            throw new BadRequestException($msg);
        }

        $resourceType->deleted = DateTime::now();
        if (!$resourcesTypesTable->save($resourceType)) {
            throw new InternalErrorException(__('The resource type could not be deleted.'));
        }
    }

    /**
     * Undo soft delete a given resource type
     *
     * @param \App\Utility\UserAccessControl $uac user access control
     * @param string $resourceTypeId uuid
     * @return void
     * @throws \Cake\Http\Exception\BadRequestException if the resource type is not deleted
     * @throws \Cake\Http\Exception\NotFoundException if resource type is not present
     */
    public function undoDelete(UserAccessControl $uac, string $resourceTypeId): void

View on GitHub (pinned to 31c1bbc10f)