Skip to content

armgit / dify

Public Imported from GitHub
0

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.

fix: model credential name (#25081)

zxhlyh67cc70ad6146
diff --git a/api/core/entities/provider_configuration.py b/api/core/entities/provider_configuration.py
index b74e081dd46..9119462aca3 100644
--- a/api/core/entities/provider_configuration.py
+++ b/api/core/entities/provider_configuration.py
@@ -410,10 +410,9 @@ class ProviderConfiguration(BaseModel):
:return:
"""
with Session(db.engine) as session:
- if credential_name and self._check_provider_credential_name_exists(
- credential_name=credential_name, session=session
- ):
- raise ValueError(f"Credential with name '{credential_name}' already exists.")
+ if credential_name:
+ if self._check_provider_credential_name_exists(credential_name=credential_name, session=session):
+ raise ValueError(f"Credential with name '{credential_name}' already exists.")
else:
credential_name = self._generate_provider_credential_name(session)
@@ -890,10 +889,11 @@ class ProviderConfiguration(BaseModel):
:return:
"""
with Session(db.engine) as session:
- if credential_name and self._check_custom_model_credential_name_exists(
- model=model, model_type=model_type, credential_name=credential_name, session=session
- ):
- raise ValueError(f"Model credential with name '{credential_name}' already exists for {model}.")
+ if credential_name:
+ if self._check_custom_model_credential_name_exists(
+ model=model, model_type=model_type, credential_name=credential_name, session=session
+ ):
+ raise ValueError(f"Model credential with name '{credential_name}' already exists for {model}.")
else:
credential_name = self._generate_custom_model_credential_name(
model=model, model_type=model_type, session=session
diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx
index adf633831b1..4ffbc8f191c 100644
--- a/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx
+++ b/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx
@@ -115,7 +115,7 @@ const ModelModal: FC<ModelModalProps> = ({
const [selectedCredential, setSelectedCredential] = useState<Credential & { addNewCredential?: boolean } | undefined>()
const formRef2 = useRef<FormRefObject>(null)
const isEditMode = !!Object.keys(formValues).filter((key) => {
- return key !== '__model_name' && key !== '__model_type'
+ return key !== '__model_name' && key !== '__model_type' && !!formValues[key]
}).length && isCurrentWorkspaceManager
const handleSave = useCallback(async () => {
@@ -167,7 +167,7 @@ const ModelModal: FC<ModelModalProps> = ({
__authorization_name__,
...rest
} = values
- if (__model_name && __model_type && __authorization_name__) {
+ if (__model_name && __model_type) {
await handleSaveCredential({
credential_id: credential?.credential_id,
credentials: rest,