{"record":{"id":"fd37eb4722250624","repo":"bitwarden/server","slug":"failed-to-remove-organization-vault-please-contac","errorCode":null,"errorMessage":"Failed to remove organization vault. Please contact support.","messagePattern":"Failed to remove organization vault\\. Please contact support\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"bitwarden_license/src/Commercial.Core/AdminConsole/Providers/RemoveOrganizationFromProviderCommand.cs","lineNumber":71,"sourceCode":"        _stripeAdapter = stripeAdapter;\n        _featureService = featureService;\n        _providerBillingService = providerBillingService;\n        _subscriberService = subscriberService;\n        _hasConfirmedOwnersExceptQuery = hasConfirmedOwnersExceptQuery;\n        _pricingClient = pricingClient;\n    }\n\n    public async Task RemoveOrganizationFromProvider(\n        Provider provider,\n        ProviderOrganization providerOrganization,\n        Organization organization)\n    {\n        if (provider == null ||\n            providerOrganization == null ||\n            organization == null ||\n            providerOrganization.ProviderId != provider.Id)\n        {\n            throw new BadRequestException(new FailedToRemoveOrganizationFromProviderError().Message);\n        }\n\n        if (!await _hasConfirmedOwnersExceptQuery.HasConfirmedOwnersExceptAsync(\n                providerOrganization.OrganizationId,\n                [],\n                includeProvider: false))\n        {\n            throw new BadRequestException(new OrgMustHaveConfirmedOwner().Message);\n        }\n\n        var organizationOwnerEmails =\n            (await _organizationRepository.GetOwnerEmailAddressesById(organization.Id)).ToList();\n\n        organization.BillingEmail = organizationOwnerEmails.MinBy(email => email);\n\n        await ResetOrganizationBillingAsync(organization, provider, organizationOwnerEmails);\n\n        await _organizationRepository.ReplaceAsync(organization);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Commercial.Core/AdminConsole/Providers/RemoveOrganizationFromProviderCommand.cs#L53-L89","documentation":"Thrown by RemoveOrganizationFromProvider when any required argument (provider, providerOrganization, organization) is null, or when providerOrganization.ProviderId does not equal provider.Id. This is a data-integrity guard ensuring the three entities are mutually consistent before detaching an org and resetting its Stripe billing. BadRequestException (HTTP 400); the message comes from the FailedToRemoveOrganizationFromProviderError error class.","triggerScenarios":"Calling RemoveOrganizationFromProvider with entities fetched from mismatched sources (providerOrganization belongs to a different provider), or when one of the lookups upstream returned null.","commonSituations":"Race condition where the providerOrganization was already deleted; stale cached IDs; provider from one request context and providerOrganization from another.","solutions":["Fetch provider, providerOrganization, and organization from a single authoritative source and assert providerOrganization.ProviderId == provider.Id before calling.","Null-check all three entities in the caller before invocation.","Handle the race gracefully (treat already-removed as success) if appropriate."],"exampleFix":"// before\nawait _removeOrgCommand.RemoveOrganizationFromProvider(provider, providerOrg, org);\n\n// after\nif (provider is null || providerOrg is null || org is null || providerOrg.ProviderId != provider.Id)\n    return; // already removed or inconsistent\nawait _removeOrgCommand.RemoveOrganizationFromProvider(provider, providerOrg, org);","handlingStrategy":"validation","validationCode":"if (provider is null || providerOrganization is null || organization is null\n    || providerOrganization.ProviderId != provider.Id)\n    throw new InvalidOperationException(\"Provider, providerOrganization, and organization must be non-null and consistent.\");","typeGuard":null,"tryCatchPattern":"try { await _removeOrgCommand.RemoveOrganizationFromProvider(provider, providerOrg, org); }\ncatch (BadRequestException ex) when (ex.Message.Contains(\"Failed to remove\"))\n{ /* inconsistent or missing entities; re-fetch and retry */ }","preventionTips":["Fetch all three entities from the same source in one request scope.","Assert ProviderId consistency before calling.","Handle the already-removed race as a no-op."],"tags":["provider","organization","billing","validation","data-integrity","bitwarden"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}