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.

Clean up legacy conditions data in if-else nodes to prevent misjudgments (#28148)

耐小心4486b54680bb
diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts
index 3bd43bd29a6..84dd4105653 100644
--- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts
+++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts
@@ -42,7 +42,7 @@ import type { RAGPipelineVariable } from '@/models/pipeline'
import type { WebhookTriggerNodeType } from '@/app/components/workflow/nodes/trigger-webhook/types'
import type { PluginTriggerNodeType } from '@/app/components/workflow/nodes/trigger-plugin/types'
import PluginTriggerNodeDefault from '@/app/components/workflow/nodes/trigger-plugin/default'
-
+import type { CaseItem, Condition } from '@/app/components/workflow/nodes/if-else/types'
import {
AGENT_OUTPUT_STRUCT,
FILE_STRUCT,
@@ -1305,10 +1305,7 @@ export const getNodeUsedVars = (node: Node): ValueSelector[] => {
break
}
case BlockEnum.IfElse: {
- res
- = (data as IfElseNodeType).conditions?.map((c) => {
- return c.variable_selector || []
- }) || []
+ res = []
res.push(
...((data as IfElseNodeType).cases || [])
.flatMap(c => c.conditions || [])
@@ -1480,9 +1477,22 @@ export const getNodeUsedVarPassToServerKey = (
break
}
case BlockEnum.IfElse: {
- const targetVar = (data as IfElseNodeType).conditions?.find(
- c => c.variable_selector?.join('.') === valueSelector.join('.'),
- )
+ const findConditionInCases = (cases: CaseItem[]): Condition | undefined => {
+ for (const caseItem of cases) {
+ for (const condition of caseItem.conditions || []) {
+ if (condition.variable_selector?.join('.') === valueSelector.join('.'))
+ return condition
+
+ if (condition.sub_variable_condition) {
+ const found = findConditionInCases([condition.sub_variable_condition])
+ if (found)
+ return found
+ }
+ }
+ }
+ return undefined
+ }
+ const targetVar = findConditionInCases((data as IfElseNodeType).cases || [])
if (targetVar) res = `#${valueSelector.join('.')}#`
break
}
@@ -1634,13 +1644,6 @@ export const updateNodeVars = (
}
case BlockEnum.IfElse: {
const payload = data as IfElseNodeType
- if (payload.conditions) {
- payload.conditions = payload.conditions.map((c) => {
- if (c.variable_selector?.join('.') === oldVarSelector.join('.'))
- c.variable_selector = newVarSelector
- return c
- })
- }
if (payload.cases) {
payload.cases = payload.cases.map((caseItem) => {
if (caseItem.conditions) {
diff --git a/web/app/components/workflow/nodes/if-else/use-single-run-form-params.ts b/web/app/components/workflow/nodes/if-else/use-single-run-form-params.ts
index 8bf667e0cca..4f07f072ccf 100644
--- a/web/app/components/workflow/nodes/if-else/use-single-run-form-params.ts
+++ b/web/app/components/workflow/nodes/if-else/use-single-run-form-params.ts
@@ -89,15 +89,6 @@ const useSingleRunFormParams = ({
inputVarsFromValue.push(...getInputVarsFromCase(caseItem))
})
}
-
- if (payload.conditions && payload.conditions.length) {
- payload.conditions.forEach((condition) => {
- const conditionVars = getVarSelectorsFromCondition(condition)
- allInputs.push(...conditionVars)
- inputVarsFromValue.push(...getInputVarsFromConditionValue(condition))
- })
- }
-
const varInputs = [...varSelectorsToVarInputs(allInputs), ...inputVarsFromValue]
// remove duplicate inputs
const existVarsKey: Record<string, boolean> = {}
@@ -148,13 +139,6 @@ const useSingleRunFormParams = ({
vars.push(...caseVars)
})
}
-
- if (payload.conditions && payload.conditions.length) {
- payload.conditions.forEach((condition) => {
- const conditionVars = getVarFromCondition(condition)
- vars.push(...conditionVars)
- })
- }
return vars
}
return {
diff --git a/web/app/components/workflow/utils/workflow-init.ts b/web/app/components/workflow/utils/workflow-init.ts
index 92233f8d081..08d0d82e79f 100644
--- a/web/app/components/workflow/utils/workflow-init.ts
+++ b/web/app/components/workflow/utils/workflow-init.ts
@@ -242,6 +242,11 @@ export const initialNodes = (originNodes: Node[], originEdges: Edge[]) => {
...(node.data as IfElseNodeType).cases.map(item => ({ id: item.case_id, name: '' })),
{ id: 'false', name: '' },
])
+ // delete conditions and logical_operator if cases is not empty
+ if (nodeData.cases.length > 0 && nodeData.conditions && nodeData.logical_operator) {
+ delete nodeData.conditions
+ delete nodeData.logical_operator
+ }
}
if (node.data.type === BlockEnum.QuestionClassifier) {