{"record":{"id":"99fe8408e10ae06e","repo":"bitwarden/server","slug":"organization-providerorganization-id-not-found","errorCode":null,"errorMessage":"Organization '{providerOrganization.Id}' not found.","messagePattern":"Organization '(.+?)' not found\\.","errorType":"exception","errorClass":"ConflictException","httpStatus":409,"severity":"error","filePath":"bitwarden_license/src/Commercial.Core/Billing/Providers/Services/ProviderBillingService.cs","lineNumber":217,"sourceCode":"            ]\n        };\n\n        await stripeAdapter.UpdateSubscriptionAsync(provider.GatewaySubscriptionId, updateOptions);\n\n        // Refactor later to ?ChangeClientPlanCommand? (ProviderPlanId, ProviderId, OrganizationId)\n        // 1. Retrieve PlanType and PlanName for ProviderPlan\n        // 2. Assign PlanType & PlanName to Organization\n        var providerOrganizations =\n            await providerOrganizationRepository.GetManyDetailsByProviderAsync(providerPlan.ProviderId);\n\n        var newPlan = await pricingClient.GetPlanOrThrow(newPlanType);\n\n        foreach (var providerOrganization in providerOrganizations)\n        {\n            var organization = await organizationRepository.GetByIdAsync(providerOrganization.OrganizationId);\n            if (organization == null)\n            {\n                throw new ConflictException($\"Organization '{providerOrganization.Id}' not found.\");\n            }\n\n            organization.PlanType = newPlanType;\n            organization.Plan = newPlan.Name;\n            await organizationRepository.ReplaceAsync(organization);\n        }\n    }\n\n    public async Task CreateCustomerForClientOrganization(\n        Provider provider,\n        Organization organization)\n    {\n        ArgumentNullException.ThrowIfNull(provider);\n        ArgumentNullException.ThrowIfNull(organization);\n\n        if (!string.IsNullOrEmpty(organization.GatewayCustomerId))\n        {\n            logger.LogWarning(\"Client organization ({ID}) already has a populated {FieldName}\", organization.Id,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Commercial.Core/Billing/Providers/Services/ProviderBillingService.cs#L199-L235","documentation":"Thrown by ProviderBillingService.ChangePlan while propagating a new plan type to a provider's client organizations: for a providerOrganization detail row, the underlying Organization (organizationRepository.GetByIdAsync) returns null. The ProviderOrganization exists but the Organization it references does not. ConflictException (HTTP 409) reflecting a referential-integrity conflict.","triggerScenarios":"A ProviderOrganization row points at an OrganizationId whose Organization row was deleted or never inserted; orphaned provider-org linkage after a failed org deletion.","commonSituations":"Data-integrity issue: an organization was hard-deleted without removing its ProviderOrganization; a partially-failed migration; manual DB edits.","solutions":["Investigate and repair the orphaned ProviderOrganization row (remove it or restore the Organization).","Add a cleanup step that prunes ProviderOrganizations whose OrganizationId no longer resolves.","Run a referential-integrity check across ProviderOrganization -> Organization before bulk plan changes."],"exampleFix":"// before\nawait providerBillingService.ChangePlan(command); // throws if any org is missing\n\n// after — pre-clean orphaned provider organizations\nvar details = await providerOrganizationRepository.GetManyDetailsByProviderAsync(providerPlan.ProviderId);\nforeach (var d in details)\n    if (await organizationRepository.GetByIdAsync(d.OrganizationId) == null)\n        await providerOrganizationRepository.DeleteAsync(d); // remove orphan\nawait providerBillingService.ChangePlan(command);","handlingStrategy":"validation","validationCode":"foreach (var d in details) if (await organizationRepository.GetByIdAsync(d.OrganizationId) == null) return Conflict($\"Org {d.Id} missing.\");","typeGuard":null,"tryCatchPattern":"try { await providerBillingService.ChangePlan(command); }\ncatch (ConflictException ex) when (ex.Message.Contains(\"not found\")) { /* prune orphan ProviderOrganization, retry */ }","preventionTips":["Run referential-integrity checks before bulk plan changes.","Clean up orphaned ProviderOrganization rows when orgs are deleted."],"tags":["billing","provider","data-integrity","orphan","conflict"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}