diff --git a/api/core/provider_manager.py b/api/core/provider_manager.py index c538a557fb..ed34922346 100644 --- a/api/core/provider_manager.py +++ b/api/core/provider_manager.py @@ -196,6 +196,8 @@ class ProviderManager: if preferred_provider_type_record: preferred_provider_type = ProviderType.value_of(preferred_provider_type_record.preferred_provider_type) + elif dify_config.EDITION == "CLOUD" and system_configuration.enabled: + preferred_provider_type = ProviderType.SYSTEM elif custom_configuration.provider or custom_configuration.models: preferred_provider_type = ProviderType.CUSTOM elif system_configuration.enabled: diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.py index 583453f6e5..ca83742d65 100644 --- a/api/services/plugin/plugin_service.py +++ b/api/services/plugin/plugin_service.py @@ -534,6 +534,13 @@ class PluginService: plugin_id = plugin.plugin_id logger.info("Deleting credentials for plugin: %s", plugin_id) + session.execute( + delete(TenantPreferredModelProvider).where( + TenantPreferredModelProvider.tenant_id == tenant_id, + TenantPreferredModelProvider.provider_name.like(f"{plugin_id}/%"), + ) + ) + # Delete provider credentials that match this plugin credential_ids = session.scalars( select(ProviderCredential.id).where( @@ -569,13 +576,6 @@ class PluginService: ) ) - session.execute( - delete(TenantPreferredModelProvider).where( - TenantPreferredModelProvider.tenant_id == tenant_id, - TenantPreferredModelProvider.provider_name.like(f"{plugin_id}/%"), - ) - ) - logger.info( "Completed deleting credentials and cleaning provider associations for plugin: %s", plugin_id,