fix: update secret environment variable description (#41309)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user