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
- Verify every collection ID in the request still exists via _collectionRepository.GetManyByManyIdsAsync before calling ValidateAsync.
- Remove or replace deleted collection IDs from the request payload.
- 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
- Refresh the client's collection list before showing the access-rule form.
- Filter out collection IDs that are no longer present in the UI before submit.
- Log missing IDs to help identify stale references.
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
- One or more collections do not belong to this organization.
- One or more collections are already governed by another acce
- A rule with that name already exists.
- Failed to remove organization vault. Please contact support.
- Name is required.
AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13).
Data as JSON: /api/errors/782e6f4595154c8f.
Report an issue: GitHub.