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(web): guard LLM node model_selector against persisted null (#41707)

Benjamin8f7cca3ae280
diff --git a/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts b/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts
index b54380a3a4c..89bea169235 100644
--- a/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts
+++ b/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts
@@ -1,4 +1,8 @@
-import type { EnvironmentVariable, ModelConfig } from '@/app/components/workflow/types'
+import type {
+ EnvironmentVariable,
+ ModelConfig,
+ ValueSelector,
+} from '@/app/components/workflow/types'
import { AppModeEnum } from '@/types/app'
import {
getLLMEnvironmentModel,
@@ -160,5 +164,14 @@ describe('llm utils', () => {
expect(isEnvironmentModelSource(selector)).toBe(false)
expect(resolveLLMNodeModel(model, selector, environmentVariables)).toBe(model)
})
+
+ it('keeps the static model when the persisted selector is null', () => {
+ // A DSL exported from an older/AI-generated workflow can persist `model_selector: null`
+ // instead of omitting the key; this must not crash the same way `undefined` doesn't.
+ const selector = null as unknown as ValueSelector
+
+ expect(isEnvironmentModelSource(selector)).toBe(false)
+ expect(resolveLLMNodeModel(model, selector, environmentVariables)).toBe(model)
+ })
})
})
diff --git a/web/app/components/workflow/nodes/llm/utils.ts b/web/app/components/workflow/nodes/llm/utils.ts
index 5ddadb70c07..f4cbd69649a 100644
--- a/web/app/components/workflow/nodes/llm/utils.ts
+++ b/web/app/components/workflow/nodes/llm/utils.ts
@@ -24,7 +24,7 @@ const isLLMEnvironmentVariableValue = (value: unknown): value is LLMEnvironmentV
}
export const isEnvironmentModelSource = (modelSelector: ValueSelector | undefined) =>
- modelSelector !== undefined && (modelSelector.length === 0 || modelSelector[0] === 'env')
+ modelSelector != null && (modelSelector.length === 0 || modelSelector[0] === 'env')
export const getLLMEnvironmentModel = (
modelSelector: ValueSelector | undefined,