ISSUE DESCRIPTION [Filters] Backend do not accept conditional groups Describe the issue…
- User
ISSUE DESCRIPTION
[Filters] Backend do not accept conditional groups
Describe the issue
HTTP 400 is returned at a simple conditional group filter query.
Reproduction
- Navigate to the Executions view
- Add a new conditional group to the default set of filters
- Keep the
ORoperator - Add a new filer - e.g. labels
foo:bar - HTTP 400 response with:
Invalid query filters: Provided query filters are invalid: Field TIME_RANGE is not supported for resource EXECUTION. Supported fields are QUERY, SCOPE, FLOW_ID, START_DATE, END_DATE, STATE, LABELS, TRIGGER_EXECUTION_ID, CHILD_FILTER, NAMESPACE, KIND, PARENT_ID
Environment
- Kestra Version: develop
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Assistant
Let me explore the repository structure to understand what we're working with.
Assistant
This is a Java/Kestra project. The issue is about conditional group filters. Let me search for the relevant filter-related code.
Assistant
Let me see the full file, especially the
validateQueryFiltersmethod and thecollectValidationErrorsmethod. I noticecollectValidationErrorsdoes handle node filters by recursing into children. But the error message says "Field TIME_RANGE is not supported for resource EXECUTION" - this means TIME_RANGE is being added somehow. Let me look at where filters are being built/added.Let me look at the QueryFilterUtils and the format binder.
Assistant
Now I see the issue. The
replaceTimeRangeWithComputedDateFiltermethod andupdateFilters/updateFiltersForEndDatemethods operate on flat lists of filters usingstream().map(...). When there are conditional groups (node filters with children), thestream().map()only handles top-level filters. The children inside a node filter are not processed, so a TIME_RANGE filter inside a conditional group would not be replaced/removed.Wait, but the error says "Field TIME_RANGE is not supported for resource EXECUTION". This means the TIME_RANGE filter is still present when validation happens. Let me look at the flow - where
replaceTimeRangeWithComputedDateFilteris called and wherevalidateQueryFiltersis called.Let me look at the ExecutionController and the filter binder.
Assistant
I see -
TimeLineSearch.extractFromiterates over filters and accessesfilter.field()without checking if the filter is a node. For a node filter,field()is null, so it continues. But the children are not searched.Let me look at the ExecutionController to understand the flow.
Assistant
So the JDBC repository's
toConditionhandles node filters (conditional groups) by recursing into children. AndvalidateQueryFiltersalso handles nodes by recursing. So the validation and condition building handle conditional groups.The issue is that
replaceTimeRangeWithComputedDateFilter(called in ExecutionController before passing to the repository) doesn't handle node filters. It usesstream().map()on the top-level list, which doesn't recurse into children. So a TIME_RANGE filter inside a conditional group would NOT be replaced/removed.Wait, but actually the issue says "Add a new conditional group to the default set of filters, Keep the OR operator, Add a new filter - e.g. labels foo:bar". So the user adds a conditional group with a labels filter. But the error mentions TIME_RANGE. Where does TIME_RANGE come from?
Looking at the default filters - the Executions view likely adds a default TIME_RANGE filter. When the user adds a conditional group, the TIME_RANGE is at the top level. Then
replaceTimeRangeWithComputedDateFiltershould replace it... but wait, let me re-read.Actually, let me re-read the error. The error is "Field TIME_RANGE is not supported for resource EXECUTION". This means TIME_RANGE is reaching and TIME_RANGE is not in the EXECUTION supported fields list.
Assistant
So EXECUTION doesn't support TIME_RANGE. The TIME_RANGE filter needs to be replaced by
replaceTimeRangeWithComputedDateFilterbefore reachingvalidateQueryFilters.The issue: when a conditional group (node filter) is added, the
replaceTimeRangeWithComputedDateFilterusesTimeLineSearch.extractFrom(filters)andupdateFilters/updateFiltersForEndDate. These iterate over the top-level filters only. The TIME_RANGE filter is at the top level (the default set), so it should be replaced...Wait, but maybe the issue is different. Let me look at the ExecutionController to see the flow more carefully. Let me look at lines around 250.
Assistant
Let me look at the
QueryFilterFormatBinderto understand how filters are parsed.Assistant
Let me look at the test files to understand the expected behavior.
Assistant
Let me look at the QueryFilterTest to see how conditional groups are tested.
Assistant
Let me look at the frontend code to understand how conditional groups are sent.
Assistant
Let me look at the filter component structure.
Assistant
The filter logic for conditional groups seems to be elsewhere. Let me search more broadly.
Assistant
The filter building for conditional groups is likely in the design-system package. Let me look at the
@kestra-io/design-systemto understand how filters are built into URL params.Assistant
Now I understand the encoding. Looking at
encodeFilterGroupsToQuery: when there are multiple groups (the default set + the new conditional group),onlyOneLeafis false, so each group gets wrapped:filters[or][0],filters[or][1], etc. This means the TIME_RANGE filter (in the default set group) gets the prefixfilters[or][0], i.e., it's inside the OR conditional group!Let me verify by reproducing. Let me look at the binder test to understand the test setup.
Assistant
Let me write a reproduction test to confirm the issue. First, let me check the test structure and how to run tests.
Assistant
Now let me create a reproduction test to confirm the issue.
Assistant
The
getQueryFiltersis package-private. Let me build the filters manually instead.Assistant
The reproduction confirms the issue. The
replaceTimeRangeWithComputedDateFilterdoes not recurse into the OR node's children, so the TIME_RANGE filter remains inside the OR node, and a default START_DATE is added at the top level (becausehasDateFilteris false).Let me check
DateUtils.validateTimeline.Assistant
DateUtils.validateTimeline(List<QueryFilter>)also doesn't recurse into children. After my fix, the START_DATE/END_DATE might be inside a node, so this validation wouldn't find them. But this validation just checks startDate <= endDate. If they're in different branches of an OR, they shouldn't necessarily be compared... Actually, this is a minor validation. But to be safe and correct, I should make this recursive too. ButDateUtilsis in core. Let me consider whether to modify it.Actually, after my fix to
updateFilters, the TIME_RANGE inside a node becomes a START_DATE inside the node. ThenvalidateTimeline(updatedFilters)is called on the updated filters. The START_DATE is now inside the node, soDateUtils.validateTimelinewon't find it. That's fine - it just won't validate, which is acceptable (no false positive). But to be thorough, let me make it recursive too.Hmm, but
DateUtils.validateTimeline(filters)is also called inQueryFilterUtils.validateTimeline. Let me check where else it's used.Assistant
Let me make
DateUtils.validateTimeline(List<QueryFilter>)recursive too, to be safe. It's a small change.Now let me implement the fixes. Let me start with
TimeLineSearch.extractFrom.Assistant
No python. Let me use the
editcommand directly.Assistant
I need to be careful with the recursion—when a child has a TIME_RANGE,
extractFromresolves it to a startDate, which would then conflict. Let me write a clean recursive raw collector instead.Assistant
Now let me fix
QueryFilterUtils. Let me makeupdateFilters,updateFiltersForEndDate, andrewriteTriggerDateFiltersrecursive.Assistant
Now let me rewrite the three methods to recurse into conditional groups. Let me edit
updateFiltersfirst.Assistant
Now let me edit
updateFiltersForEndDate(lines 82-98):Assistant
Now let me edit
rewriteTriggerDateFilters(lines 147-166):Assistant
Now I need to add the helper methods
anyLeafMatchandmapFilters. Let me add them before the class closing brace.Assistant
I see a problem—the
});that closes the lambda andmapFilterscall was removed. Let me check and fix lines 162-164.Assistant
Yes, the
});is missing. Line 162 isreturn f;and line 163 is}. I need to fix: line 163 should be});(close lambda + mapFilters call) and then add}to close the method.Let me edit line 163.
Assistant
Now let me also make
DateUtils.validateTimeline(List<QueryFilter>)recursive, to handle the case where START_DATE/END_DATE are nested inside conditional groups (after replacement).Assistant
Let me make
validateTimeline(List<QueryFilter>)recursive.Assistant
There are leftover duplicate lines 140-143. Let me remove them.
Assistant
The edit removed the closing brace of the method. Let me fix line 138-139 to add the closing brace.
Assistant
Let me add a blank line between line 139 and 140 for formatting.
Assistant
Now let me run the reproduction test to confirm the fix.
Assistant
The fix works. Now let me run the existing related tests to make sure I didn't break anything.
Assistant
Let me check the TimeLineSearchTest to understand what it tests (it seems to test
updateFilterswhich is package-protected).Assistant
Good, these tests pass. Now let me run the core
QueryFilterTestand the JDBCAbstractJdbcRepositoryTest.Assistant
Let me run the
ExecutionControllerTestwhich has tests around query filters and the validation error message.Assistant
All tests pass. Let me check the JDBC repository tests for conditional group condition building to ensure those still work.
Assistant
Let me look at the AbstractJdbcRepositoryTest to understand what it tests, especially around conditional groups / TIME_RANGE.
Assistant
Let me search for conditional group tests in the execution repository tests.
Assistant
There are existing tests for conditional groups in the execution repository. Let me run the H2 execution repository tests to ensure the condition building works end-to-end.
Assistant
Let me check whether the
should_find_alltest passes a TIME_RANGE filter directly to the repository.Assistant
This test
should_fail_to_find_allconfirms that TIME_RANGE is correctly rejected by the repository (it must be replaced before reaching it). My fix is in the right place.Let me check the DashboardController and MetricController to ensure they still work with the recursive
validateTimeline.Assistant
Let me look at the DashboardController around line 291 to see how filters are usedthere.
Assistant
The DashboardController's
formatLabelsFiltersdoesn't recurse, but that's a dashboard-specific path and not part of the reported issue (Executions view). Let me focus on the reported issue. Let me expand my reproduction test to cover edge cases (deeply nested, top-level + sibling group, START_DATE inside group).Assistant
All edge cases pass. Let me also verify the trigger flow (
rewriteTriggerDateFilters) with a nested TIME_RANGE.Assistant
It says UP-TO-DATE because I didn't change the test file content since last run (the perl substitution might have produced the same content). Let me force re-run with --rerun-tasks or clean the test. Actually, the test was UP-TO-DATE meaning it didn't recompile. But I modified the file. Let me check the file content.
Assistant
All 5 tests pass. Let me run the Log and Trigger controller tests to be safe.
Assistant
Let me run the H2 log and trigger repository tests to be safe.
Assistant
All passing. Now let me remove the temporary test file and review the final diff.
Assistant
The diff looks clean. Let me check if there are any tests directly testing
DateUtils.validateTimeline(List).Assistant
No tests directly test
validateTimelinein test files. Let me run the DashboardControllerTest to make sure dashboards still work.Assistant
All tests pass. Let me do a final compile check across the affected modules to ensure everything compiles cleanly.
Assistant
Everything compiles. Let me verify the final git status shows only the 3 modified files (no leftover temp test).
Assistant
Assistant
The changes are confirmed. Let me do a final verification that everything is in order beforesubmitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.