mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-19 18:05:41 -05:00
fix(filters): change label filtering to 'and' instead of 'or' (#8661)
* fix(filters): change label filtering to 'and' instead of 'or' link to #8489 * test(execution): add test to validate and behavior * test(execution): fix test
This commit is contained in:
@@ -191,7 +191,7 @@ public abstract class AbstractExecutionRepositoryTest {
|
||||
.build()
|
||||
);
|
||||
executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters);
|
||||
assertThat(executions.getTotal()).isEqualTo(1L);
|
||||
assertThat(executions.getTotal()).isEqualTo(0L);
|
||||
|
||||
filters = List.of(QueryFilter.builder()
|
||||
.field(QueryFilter.Field.FLOW_ID)
|
||||
@@ -816,4 +816,26 @@ public abstract class AbstractExecutionRepositoryTest {
|
||||
List<Execution> executions = executionRepository.findAllAsync(MAIN_TENANT).collectList().block();
|
||||
assertThat(executions).hasSize(29); // used by the backup so it contains TEST executions
|
||||
}
|
||||
|
||||
@Test
|
||||
protected void shouldFindByLabel() {
|
||||
inject();
|
||||
|
||||
List<QueryFilter> filters = List.of(QueryFilter.builder()
|
||||
.field(QueryFilter.Field.LABELS)
|
||||
.operation(QueryFilter.Op.EQUALS)
|
||||
.value(Map.of("key", "value"))
|
||||
.build());
|
||||
List<Execution> executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters);
|
||||
assertThat(executions.size()).isEqualTo(1L);
|
||||
|
||||
// Filtering by two pairs of labels, since now its a and behavior, it should not return anything
|
||||
filters = List.of(QueryFilter.builder()
|
||||
.field(QueryFilter.Field.LABELS)
|
||||
.operation(QueryFilter.Op.EQUALS)
|
||||
.value(Map.of("key", "value", "keyother", "valueother"))
|
||||
.build());
|
||||
executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters);
|
||||
assertThat(executions.size()).isEqualTo(0L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ public abstract class H2ExecutionRepositoryService {
|
||||
});
|
||||
|
||||
|
||||
return conditions.isEmpty() ? DSL.trueCondition() : DSL.or(conditions);
|
||||
return conditions.isEmpty() ? DSL.trueCondition() : DSL.and(conditions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class MysqlExecutionRepositoryService {
|
||||
|
||||
});
|
||||
|
||||
return conditions.isEmpty() ? DSL.trueCondition() : DSL.or(conditions);
|
||||
return conditions.isEmpty() ? DSL.trueCondition() : DSL.and(conditions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import io.kestra.core.models.QueryFilter;
|
||||
import io.kestra.core.models.executions.Execution;
|
||||
import io.kestra.jdbc.AbstractJdbcRepository;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -44,7 +43,7 @@ public abstract class PostgresExecutionRepositoryService {
|
||||
|
||||
});
|
||||
|
||||
return conditions.isEmpty() ? DSL.trueCondition() : DSL.or(conditions);
|
||||
return conditions.isEmpty() ? DSL.trueCondition() : DSL.and(conditions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user