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: update secret environment variable description (#41309)

Xin Zhang638dfd77a484
diff --git a/api/models/workflow.py b/api/models/workflow.py
index fa44dee7ec0..dd021307fd9 100644
--- a/api/models/workflow.py
+++ b/api/models/workflow.py
@@ -644,11 +644,13 @@ class Workflow(Base): # bug
raise ValueError("environment variable require a unique id")
# Compare inputs and origin variables,
- # if the value is HIDDEN_VALUE, use the origin variable value (only update `name`).
+ # if the value is HIDDEN_VALUE, use the origin variable value.
origin_variables_dictionary = {var.id: var for var in self.environment_variables}
for i, variable in enumerate(value):
if variable.id in origin_variables_dictionary and variable.value == HIDDEN_VALUE:
- value[i] = origin_variables_dictionary[variable.id].model_copy(update={"name": variable.name})
+ value[i] = origin_variables_dictionary[variable.id].model_copy(
+ update={"name": variable.name, "description": variable.description}
+ )
# encrypt secret variables value
def encrypt_func(var: VariableBase) -> VariableBase:
diff --git a/api/tests/unit_tests/models/test_workflow.py b/api/tests/unit_tests/models/test_workflow.py
index 8c202450ff4..ed6d4ed88c7 100644
--- a/api/tests/unit_tests/models/test_workflow.py
+++ b/api/tests/unit_tests/models/test_workflow.py
@@ -103,7 +103,13 @@ def test_update_environment_variables():
# Create some EnvironmentVariable instances
variable1 = StringVariable(name="var1", value="value1", id=str(uuid4()), selector=["env", "var1"])
variable2 = IntegerVariable(name="var2", value=123, id=str(uuid4()), selector=["env", "var2"])
- variable3 = SecretVariable(name="var3", value="secret", id=str(uuid4()), selector=["env", "var3"])
+ variable3 = SecretVariable(
+ name="var3",
+ value="secret",
+ id=str(uuid4()),
+ selector=["env", "var3"],
+ description="old description",
+ )
variable4 = FloatVariable(name="var4", value=3.14, id=str(uuid4()), selector=["env", "var4"])
with (
@@ -116,16 +122,18 @@ def test_update_environment_variables():
workflow.environment_variables = variables
assert workflow.environment_variables == [variable1, variable2, variable3, variable4]
- # Update the name of variable3 and keep the value as it is
+ # Update the name and description of variable3 and keep the value as it is
variables[2] = variable3.model_copy(
update={
"name": "new name",
+ "description": "new description",
"value": HIDDEN_VALUE,
}
)
workflow.environment_variables = variables
assert workflow.environment_variables[2].name == "new name"
+ assert workflow.environment_variables[2].description == "new description"
assert workflow.environment_variables[2].value == variable3.value