lfnovo/open-notebook · error · HTTPException
Failed to delete credential
Error message
Failed to delete credential
What it means
Catch-all 500 from DELETE /api/credentials/{credential_id}. The delete endpoint supports a migrate_to query param that moves or deletes linked models first; any unexpected exception in that migration/deletion logic or the DB writes surfaces here.
Source
Thrown at api/routers/credentials.py:403
deleted_models += 1
# Delete the credential
await cred.delete()
return CredentialDeleteResponse(
message="Credential deleted successfully",
deleted_models=deleted_models,
)
except HTTPException:
raise
except NotFoundError:
raise HTTPException(status_code=404, detail="Credential not found")
except OpenNotebookError:
raise
except Exception as e:
logger.error(f"Error deleting credential {credential_id}: {e}")
raise HTTPException(status_code=500, detail="Failed to delete credential")
# =============================================================================
# Test / Discover / Register endpoints
# =============================================================================
@router.post("/{credential_id}/test")
async def test_credential(credential_id: str):
"""Test connection using this credential's configuration."""
return await svc_test_credential(credential_id)
@router.post("/{credential_id}/discover", response_model=DiscoverModelsResponse)
async def discover_models_for_credential(credential_id: str):
"""Discover available models using this credential's API key."""
try:
cred = await Credential.get(credential_id)View on GitHub (pinned to a7de90d38a)
Solutions
- Check logs for 'Error deleting credential <id>: ...' and inspect how far the migration got
- List models to see which were migrated/deleted before the failure; clean up orphans manually if needed
- Verify migrate_to points to an existing credential before retrying
- Retry the delete once DB health is confirmed; a retry after partial migration is safe if migrate_to still resolves
Defensive patterns
Strategy: try-catch
Validate before calling
// verify migrate_to target exists before delete-with-migration
if (migrateTo) {
const creds = await api.listCredentials();
if (!creds.some(c => c.id === migrateTo)) throw new Error('Migration target credential not found');
} Try / catch
try {
await api.deleteCredential(id, { migrate_to: migrateTo });
} catch (e) {
if (e.status === 500) {
// partial migration possible: audit linked models before retrying
await auditModelsForCredential(id);
}
throw e;
} Prevention
- Validate the migrate_to credential exists first
- Audit linked models after a failed delete-with-migration to catch partial state
When it happens
Trigger: DELETE with ?migrate_to=<other_credential_id> where migrating linked models fails (target credential invalid, model update error), or plain DELETE when the DB write fails partway (some linked models already deleted).
Common situations: Migrating models to a credential that was concurrently deleted, DB timeout during multi-record model updates, or partial failure leaving orphaned models.
Related errors
- Migration from provider config failed
- Migration from environment variables failed
- Error deleting session: {str(e)}
- Failed to check environment status
- Failed to list credentials
AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27).
Data as JSON: /api/errors/4e5e5396de65f66e.
Report an issue: GitHub.