{"record":{"id":"851a337733467693","repo":"plandex-ai/plandex","slug":"error-deleting-custom-providers-w","errorCode":null,"errorMessage":"error deleting custom providers: %w","messagePattern":"error deleting custom providers: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":317,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"error creating custom provider: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tfor _, modelPack := range toUpsertModelPacks {\n\t\t\tif err := db.UpsertModelPack(tx, modelPack); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating model pack: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tif len(toDeleteCustomModelIds) > 0 {\n\t\t\tif err := db.DeleteCustomModels(tx, auth.OrgId, toDeleteCustomModelIds); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error deleting custom models: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tif len(toDeleteCustomProviderIds) > 0 {\n\t\t\tif err := db.DeleteCustomProviders(tx, auth.OrgId, toDeleteCustomProviderIds); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error deleting custom providers: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tif len(toDeleteModelPackIds) > 0 {\n\t\t\tif err := db.DeleteModelPacks(tx, auth.OrgId, toDeleteModelPackIds); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error deleting model packs: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error: %v\\n\", err)\n\t\thttp.Error(w, \"Failed to import custom models/providers/model packs: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L299-L335","documentation":"Wrapped error raised in the org model-import transaction when db.DeleteCustomProviders fails while removing org custom providers absent from the submitted config. The WithTx closure aborts, rolling back all upserts and deletes, and the handler returns 500.","triggerScenarios":"POST of a custom model config where previously-defined custom providers are missing from the payload and db.DeleteCustomProviders(tx, auth.OrgId, toDeleteCustomProviderIds) hits a DB error, most often a FK violation because custom models or model packs still reference the provider.","commonSituations":"Re-importing a config that renames or drops a provider whose models are still referenced elsewhere; DB outages; concurrent imports causing deadlocks.","solutions":["Delete or replace the custom models/model packs that reference the provider in the same config payload before dropping the provider","Check server logs for the wrapped Postgres error to confirm which constraint failed","Retry after fixing; transaction rollback leaves prior state intact","Verify DB connectivity if the cause is a connection error"],"exampleFix":"// before: provider dropped while its models remain\nconfig.CustomProviders = []shared.ApiCustomProvider{}\n// after: also remove models using that provider\nconfig.CustomProviders = []shared.ApiCustomProvider{}\nconfig.CustomModels = modelsNotUsingRemovedProvider","handlingStrategy":"validation","validationCode":"// keep providers whose models are still present\nconst keptProviders = new Set(config.CustomModels.map(m => m.ProviderName))\nconfig.CustomProviders = config.CustomProviders.filter(p => keptProviders.has(p.Name))","typeGuard":"function noOrphanModels(config) {\n  const providers = new Set((config.CustomProviders ?? []).map(p => p.Name))\n  return (config.CustomModels ?? []).every(m => providers.has(m.ProviderName))\n}","tryCatchPattern":"try {\n  await client.ImportCustomModels(config)\n} catch (err) {\n  if (String(err.message).includes('error deleting custom providers')) {\n    // FK conflict: models still reference the provider; fix payload and retry\n  }\n}","preventionTips":["Only remove a provider when no custom model references it","Ship model and provider changes in the same import so deletes are consistent","Check the wrapped DB error in server logs to confirm which constraint blocked the delete"],"tags":["database","transaction","foreign-key"],"backgroundTag":"db-transaction-aborted","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}