mirror of https://github.com/langgenius/dify.git
Clean up legacy conditions data in if-else nodes to prevent misjudgments (#28148)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
parent
1a2f8dfcb4
commit
4486b54680
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue