bitwarden/server · error · BadRequestException

One or more collections could not be found.

Error message

One or more collections could not be found.

What it means

Thrown by AccessRuleWriteValidator.ValidateCollectionsAsync (line 74) after fetching collections by the submitted IDs. If _collectionRepository.GetManyByManyIdsAsync returns fewer records than the number of distinct collectionIds submitted, one or more collections do not exist in the database.

Source

Thrown at bitwarden_license/src/Services/Pam/Services/AccessRuleWriteValidator.cs:74

        if (siblings.Any(r => r.Id != existingRuleId && string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)))
        {
            throw new BadRequestException("A rule with that name already exists.");
        }
    }

    private async Task<List<Guid>> ValidateCollectionsAsync(Guid organizationId, IEnumerable<Guid> collectionIds,
        Guid? existingRuleId)
    {
        var distinctIds = collectionIds.Distinct().ToList();
        if (distinctIds.Count == 0)
        {
            return distinctIds;
        }

        var collections = await _collectionRepository.GetManyByManyIdsAsync(distinctIds);
        if (collections.Count != distinctIds.Count)
        {
            throw new BadRequestException("One or more collections could not be found.");
        }

        if (collections.Any(c => c.OrganizationId != organizationId))
        {
            throw new BadRequestException("One or more collections do not belong to this organization.");
        }

        // Deletes clear Collection.AccessRuleId and the FK forbids dangling links, so any set link points at an
        // existing rule; only a link to a different rule is a conflict. A rule being created has no id, so for it
        // any link at all conflicts.
        if (collections.Any(c => c.AccessRuleId.HasValue && c.AccessRuleId != existingRuleId))
        {
            throw new BadRequestException("One or more collections are already governed by another access rule.");
        }

        return distinctIds;
    }
}

View on GitHub (pinned to e93b962371)

Solutions

  1. Verify every collection ID in the request still exists via _collectionRepository.GetManyByManyIdsAsync before calling ValidateAsync.
  2. Remove or replace deleted collection IDs from the request payload.
  3. Ensure the client refreshes its collection list before submitting the access-rule form.

Example fix

// before — blindly pass unverified collection IDs
var ids = collectionIdsFromRequest;
await _validator.ValidateAsync(orgId, rule, ids);
// after — pre-validate existence
var existing = await _collectionRepository.GetManyByManyIdsAsync(ids.Distinct().ToList());
if (existing.Count != ids.Distinct().Count())
    return BadRequest("Some collection IDs are invalid or deleted.");
await _validator.ValidateAsync(orgId, rule, ids);
Defensive patterns

Strategy: validation

Validate before calling

var distinct = collectionIds.Distinct().ToList();
var found = await _collectionRepository.GetManyByManyIdsAsync(distinct);
if (found.Count != distinct.Count)
{
    var missing = distinct.Except(found.Select(c => c.Id));
    return BadRequest($"Unknown collection IDs: {string.Join(", ", missing)}");
}

Try / catch

try { await _validator.ValidateAsync(orgId, rule, collectionIds); }
catch (BadRequestException ex) when (ex.Message.Contains("could not be found"))
{ /* refresh collection list, re-submit */ }

Prevention

When it happens

Trigger: Calling ValidateAsync with a collectionIds list containing a GUID that has no corresponding Collection row. The fetched list count is compared against distinctIds.Count and they don't match.

Common situations: Client sends a stale or deleted collection ID; GUID is copy-pasted incorrectly from another org; collection was deleted between page load and rule save; collection ID belongs to a different database/environment.

Related errors


AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13). Data as JSON: /api/errors/782e6f4595154c8f. Report an issue: GitHub.