Skip to content

Commit f1c9d8a

Browse files
fix(flows): avoid failing flow dependencies with dynamic defaults
closes #11117
1 parent 9d3d364 commit f1c9d8a

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

core/src/main/java/io/kestra/core/runners/RunVariables.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.kestra.core.models.flows.Input;
1111
import io.kestra.core.models.flows.State;
1212
import io.kestra.core.models.flows.input.SecretInput;
13+
import io.kestra.core.models.property.Property;
1314
import io.kestra.core.models.property.PropertyContext;
1415
import io.kestra.core.models.tasks.Task;
1516
import io.kestra.core.models.triggers.AbstractTrigger;
@@ -282,15 +283,15 @@ public Map<String, Object> build(final RunContextLogger logger, final PropertyCo
282283

283284
if (flow != null && flow.getInputs() != null) {
284285
// we add default inputs value from the flow if not already set, this will be useful for triggers
285-
flow.getInputs().stream()
286-
.filter(input -> input.getDefaults() != null && !inputs.containsKey(input.getId()))
287-
.forEach(input -> {
288-
try {
289-
inputs.put(input.getId(), FlowInputOutput.resolveDefaultValue(input, propertyContext));
290-
} catch (IllegalVariableEvaluationException e) {
291-
throw new RuntimeException("Unable to inject default value for input '" + input.getId() + "'", e);
292-
}
293-
});
286+
flow.getInputs().stream()
287+
.filter(input -> input.getDefaults() != null && !inputs.containsKey(input.getId()))
288+
.forEach(input -> {
289+
try {
290+
inputs.put(input.getId(), FlowInputOutput.resolveDefaultValue(input, propertyContext));
291+
} catch (IllegalVariableEvaluationException e) {
292+
// Silent catch, if an input depends on another input, or a variable that is populated at runtime / input filling time, we can't resolve it here.
293+
}
294+
});
294295
}
295296

296297
if (!inputs.isEmpty()) {

core/src/test/java/io/kestra/core/runners/RunVariablesTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
package io.kestra.core.runners;
22

3+
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
4+
import io.kestra.core.models.executions.Execution;
5+
import io.kestra.core.models.flows.DependsOn;
36
import io.kestra.core.models.flows.Flow;
7+
import io.kestra.core.models.flows.Type;
8+
import io.kestra.core.models.flows.input.BoolInput;
9+
import io.kestra.core.models.property.Property;
410
import io.kestra.core.models.property.PropertyContext;
511
import io.kestra.core.models.tasks.Task;
612
import io.kestra.core.models.triggers.AbstractTrigger;
13+
import io.kestra.core.runners.pebble.functions.SecretFunction;
14+
import io.kestra.core.utils.IdUtils;
15+
import io.micronaut.context.ApplicationContext;
716
import org.junit.jupiter.api.Assertions;
817
import org.junit.jupiter.api.Test;
918
import org.mockito.Mockito;
1019

20+
import java.util.Collections;
21+
import java.util.List;
1122
import java.util.Map;
1223

1324
import static org.assertj.core.api.Assertions.assertThat;
@@ -112,4 +123,25 @@ void shouldGetKestraConfiguration() {
112123
assertThat(kestra.get("environment")).isEqualTo("test");
113124
assertThat(kestra.get("url")).isEqualTo("http://localhost:8080");
114125
}
115-
}
126+
127+
@Test
128+
void nonResolvableDynamicInputsShouldBeSkipped() throws IllegalVariableEvaluationException {
129+
Map<String, Object> variables = new RunVariables.DefaultBuilder()
130+
.withFlow(Flow
131+
.builder()
132+
.namespace("a.b")
133+
.id("c")
134+
.inputs(List.of(
135+
BoolInput.builder().id("a").type(Type.BOOL).defaults(Property.ofValue(true)).build(),
136+
BoolInput.builder().id("b").type(Type.BOOL).dependsOn(new DependsOn(List.of("a"), null)).defaults(Property.ofExpression("{{inputs.a == true}}")).build()
137+
))
138+
.build()
139+
)
140+
.withExecution(Execution.builder().id(IdUtils.create()).build())
141+
.build(new RunContextLogger(), PropertyContext.create(new VariableRenderer(Mockito.mock(ApplicationContext.class), Mockito.mock(VariableRenderer.VariableConfiguration.class), Collections.emptyList())));
142+
143+
Assertions.assertEquals(Map.of(
144+
"a", true
145+
), variables.get("inputs"));
146+
}
147+
}

0 commit comments

Comments
 (0)