Skip to content

Commit

Permalink
fix(core): subflow validation didn't work anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Jan 30, 2025
1 parent 1301aaa commit ceda5eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 9 additions & 7 deletions core/src/main/java/io/kestra/core/services/FlowService.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ public void checkValidSubflows(Flow flow) {
subFlows.forEach(subflow -> {
Optional<Flow> optional = findById(flow.getTenantId(), subflow.getNamespace(), subflow.getFlowId());

violations.add(ManualConstraintViolation.of(
"The subflow '" + subflow.getFlowId() + "' not found in namespace '" + subflow.getNamespace() + "'.",
flow,
Flow.class,
"flow.tasks",
flow.getNamespace()
));
if (optional.isEmpty()) {
violations.add(ManualConstraintViolation.of(
"The subflow '" + subflow.getFlowId() + "' not found in namespace '" + subflow.getNamespace() + "'.",
flow,
Flow.class,
"flow.tasks",
flow.getNamespace()
));
}
});

if (!violations.isEmpty()) {
Expand Down
22 changes: 21 additions & 1 deletion core/src/test/java/io/kestra/core/services/FlowServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertTrue;

@KestraTest
Expand Down Expand Up @@ -323,7 +324,7 @@ void findById() {
}

@Test
void checkValidSubflowsNotFound() {
void checkSubflowNotFound() {
Flow flow = create("mainFlow", "task", 1).toBuilder()
.tasks(List.of(
io.kestra.plugin.core.flow.Subflow.builder()
Expand All @@ -342,4 +343,23 @@ void checkValidSubflowsNotFound() {
assertThat(exception.getConstraintViolations().size(), is(1));
assertThat(exception.getConstraintViolations().iterator().next().getMessage(), is("The subflow 'nonExistentSubflow' not found in namespace 'io.kestra.unittest'."));
}

@Test
void checkValidSubflow() {
Flow subflow = create("existingSubflow", "task", 1);
flowRepository.create(subflow, subflow.generateSource(), subflow);

Flow flow = create("mainFlow", "task", 1).toBuilder()
.tasks(List.of(
io.kestra.plugin.core.flow.Subflow.builder()
.id("subflowTask")
.type(io.kestra.plugin.core.flow.Subflow.class.getName())
.namespace("io.kestra.unittest")
.flowId("existingSubflow")
.build()
))
.build();

assertDoesNotThrow(() -> flowService.checkValidSubflows(flow));
}
}

0 comments on commit ceda5eb

Please sign in to comment.