Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: Add option to delete or keep API keys when uninstalling plugin (#28201)
UMDKyle7f9884e7a1d5
diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.pyindex b8303eb7240..411c335c175 100644--- a/api/services/plugin/plugin_service.py+++ b/api/services/plugin/plugin_service.py@@ -3,6 +3,7 @@ from collections.abc import Mapping, Sequencefrom mimetypes import guess_typefrom pydantic import BaseModel+from sqlalchemy import selectfrom yarl import URLfrom configs import dify_config@@ -25,7 +26,9 @@ from core.plugin.entities.plugin_daemon import (from core.plugin.impl.asset import PluginAssetManagerfrom core.plugin.impl.debugging import PluginDebuggingClientfrom core.plugin.impl.plugin import PluginInstaller+from extensions.ext_database import dbfrom extensions.ext_redis import redis_client+from models.provider import ProviderCredentialfrom models.provider_ids import GenericProviderIDfrom services.errors.plugin import PluginInstallationForbiddenErrorfrom services.feature_service import FeatureService, PluginInstallationScope@@ -506,6 +509,33 @@ class PluginService:@staticmethoddef uninstall(tenant_id: str, plugin_installation_id: str) -> bool:manager = PluginInstaller()++ # Get plugin info before uninstalling to delete associated credentials+ try:+ plugins = manager.list_plugins(tenant_id)+ plugin = next((p for p in plugins if p.installation_id == plugin_installation_id), None)++ if plugin:+ plugin_id = plugin.plugin_id+ logger.info("Deleting credentials for plugin: %s", plugin_id)++ # Delete provider credentials that match this plugin+ credentials = db.session.scalars(+ select(ProviderCredential).where(+ ProviderCredential.tenant_id == tenant_id,+ ProviderCredential.provider_name.like(f"{plugin_id}/%"),+ )+ ).all()++ for cred in credentials:+ db.session.delete(cred)++ db.session.commit()+ logger.info("Deleted %d credentials for plugin: %s", len(credentials), plugin_id)+ except Exception as e:+ logger.warning("Failed to delete credentials: %s", e)+ # Continue with uninstall even if credential deletion fails+return manager.uninstall(tenant_id, plugin_installation_id)@staticmethod