From b892906d714a004347ad9178749cdded248b07ab Mon Sep 17 00:00:00 2001 From: wangxiaolei Date: Fri, 26 Dec 2025 10:40:30 +0800 Subject: [PATCH] fix: fix metadata filter not survive a rename (#30174) --- .../app/configuration/dataset-config/index.tsx | 3 ++- .../metadata/condition-list/condition-item.tsx | 9 ++++++++- .../components/metadata/metadata-trigger.tsx | 10 ++++++++-- .../workflow/nodes/knowledge-retrieval/types.ts | 1 + .../workflow/nodes/knowledge-retrieval/use-config.ts | 3 ++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/web/app/components/app/configuration/dataset-config/index.tsx b/web/app/components/app/configuration/dataset-config/index.tsx index 2fc82c82b6..f5324f40d8 100644 --- a/web/app/components/app/configuration/dataset-config/index.tsx +++ b/web/app/components/app/configuration/dataset-config/index.tsx @@ -176,7 +176,7 @@ const DatasetConfig: FC = () => { })) }, [setDatasetConfigs, datasetConfigsRef]) - const handleAddCondition = useCallback(({ name, type }) => { + const handleAddCondition = useCallback(({ id, name, type }) => { let operator: ComparisonOperator = ComparisonOperator.is if (type === MetadataFilteringVariableType.number) @@ -184,6 +184,7 @@ const DatasetConfig: FC = () => { const newCondition = { id: uuid4(), + metadata_id: id, // Save metadata.id for reliable reference name, comparison_operator: operator, } diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx index 815844d434..17fbd8ebca 100644 --- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx +++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx @@ -62,8 +62,15 @@ const ConditionItem = ({ }, [onRemoveCondition, condition.id]) const currentMetadata = useMemo(() => { + // Try to match by metadata_id first (reliable reference) + if (condition.metadata_id) { + const found = metadataList.find(metadata => metadata.id === condition.metadata_id) + if (found) + return found + } + // Fallback to name matching for backward compatibility with old conditions return metadataList.find(metadata => metadata.name === condition.name) - }, [metadataList, condition.name]) + }, [metadataList, condition.metadata_id, condition.name]) const handleConditionOperatorChange = useCallback((operator: ComparisonOperator) => { onUpdateCondition?.( diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/metadata-trigger.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/metadata-trigger.tsx index 3a8d96f8f2..82f0decc01 100644 --- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/metadata-trigger.tsx +++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/metadata-trigger.tsx @@ -27,11 +27,17 @@ const MetadataTrigger = ({ useEffect(() => { if (selectedDatasetsLoaded) { conditions.forEach((condition) => { - if (!metadataList.find(metadata => metadata.name === condition.name)) + // First try to match by metadata_id for reliable reference + const foundById = condition.metadata_id && metadataList.find(metadata => metadata.id === condition.metadata_id) + // Fallback to name matching only for backward compatibility with old conditions + const foundByName = !condition.metadata_id && metadataList.find(metadata => metadata.name === condition.name) + + // Only remove condition if both metadata_id and name matching fail + if (!foundById && !foundByName) handleRemoveCondition(condition.id) }) } - }, [metadataList, handleRemoveCondition, selectedDatasetsLoaded]) + }, [metadataFilteringConditions, metadataList, handleRemoveCondition, selectedDatasetsLoaded]) return ( { })) }, [setInputs]) - const handleAddCondition = useCallback(({ name, type }) => { + const handleAddCondition = useCallback(({ id, name, type }) => { let operator: ComparisonOperator = ComparisonOperator.is if (type === MetadataFilteringVariableType.number) @@ -313,6 +313,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => { const newCondition = { id: uuid4(), + metadata_id: id, // Save metadata.id for reliable reference name, comparison_operator: operator, }