plandex-ai/plandex · error

error deleting custom providers: %w

Error message

error deleting custom providers: %w

What it means

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.

Source

Thrown at app/server/handlers/models.go:317

				return fmt.Errorf("error creating custom provider: %w", err)
			}
		}

		for _, modelPack := range toUpsertModelPacks {
			if err := db.UpsertModelPack(tx, modelPack); err != nil {
				return fmt.Errorf("error creating model pack: %w", err)
			}
		}

		if len(toDeleteCustomModelIds) > 0 {
			if err := db.DeleteCustomModels(tx, auth.OrgId, toDeleteCustomModelIds); err != nil {
				return fmt.Errorf("error deleting custom models: %w", err)
			}
		}

		if len(toDeleteCustomProviderIds) > 0 {
			if err := db.DeleteCustomProviders(tx, auth.OrgId, toDeleteCustomProviderIds); err != nil {
				return fmt.Errorf("error deleting custom providers: %w", err)
			}
		}

		if len(toDeleteModelPackIds) > 0 {
			if err := db.DeleteModelPacks(tx, auth.OrgId, toDeleteModelPackIds); err != nil {
				return fmt.Errorf("error deleting model packs: %w", err)
			}
		}

		return nil
	})

	if err != nil {
		log.Printf("Error: %v\n", err)
		http.Error(w, "Failed to import custom models/providers/model packs: "+err.Error(), http.StatusInternalServerError)
		return
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Delete or replace the custom models/model packs that reference the provider in the same config payload before dropping the provider
  2. Check server logs for the wrapped Postgres error to confirm which constraint failed
  3. Retry after fixing; transaction rollback leaves prior state intact
  4. Verify DB connectivity if the cause is a connection error

Example fix

// before: provider dropped while its models remain
config.CustomProviders = []shared.ApiCustomProvider{}
// after: also remove models using that provider
config.CustomProviders = []shared.ApiCustomProvider{}
config.CustomModels = modelsNotUsingRemovedProvider
Defensive patterns

Strategy: validation

Validate before calling

// keep providers whose models are still present
const keptProviders = new Set(config.CustomModels.map(m => m.ProviderName))
config.CustomProviders = config.CustomProviders.filter(p => keptProviders.has(p.Name))

Type guard

function noOrphanModels(config) {
  const providers = new Set((config.CustomProviders ?? []).map(p => p.Name))
  return (config.CustomModels ?? []).every(m => providers.has(m.ProviderName))
}

Try / catch

try {
  await client.ImportCustomModels(config)
} catch (err) {
  if (String(err.message).includes('error deleting custom providers')) {
    // FK conflict: models still reference the provider; fix payload and retry
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Re-importing a config that renames or drops a provider whose models are still referenced elsewhere; DB outages; concurrent imports causing deadlocks.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/851a337733467693. Report an issue: GitHub.