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
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
I'll start by exploring the repository to understand its structure and locate relevant files related to filters and query parsing. Let's first get a high-level view.
- Assistant
Let me explore the repository structure more broadly.
- Assistant
Let me search for filter-related code, particularly focusing on conditional groups and the TIME_RANGE field.
- Assistant
Let me look at the error message more closely. The error says:
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
This suggests that when creating a conditional group, a TIME_RANGE field is being sent that's not valid for the EXECUTION resource. Let me look at the QueryFilter model and the validation logic.
- Assistant
Let me look at the QueryFilter model and how filters are parsed.
- Assistant
Let me see the full file to understand the Resource enum and the TIME_RANGE field:
- Assistant
Let me see the EXECUTION resource definition and the TIME_RANGE field more carefully.
- Assistant
Let me see the EXECUTION resource's supported fields and the TIME_RANGE field definition.
- Assistant
Let me look at the TIME_RANGE field and the validation logic:
- Assistant
Now let me find the TIME_RANGE field definition:
- Assistant
Let me see the TIME_RANGE field definition:
- Assistant
Let me look at the QueryFilterUtils to understand how TIME_RANGE is handled:
- Assistant
Let me look at how the filter validation is called and where it might be failing:
- Assistant
Let me look at the
collectValidationErrorsmethod more carefully. The issue is likely in how the method handles child filters. The error message shows "Field TIME_RANGE is not supported for resource EXECUTION." which suggests the TIME_RANGE field is being validated against the EXECUTION resource. But looking at the supported fields for EXECUTION, TIME_RANGE is not listed. - Assistant
Now let me understand the flow. The
TimeLineSearch.extractFrommethod only iterates top-level filters. IfTIME_RANGEis inside a conditional group (node), it won't be extracted, and it'll be passed to the validation as-is. Let me check how the filters are processed: - Assistant
The issue is about conditional groups in filters. When a user adds a conditional group (with OR/AND logical operator and children), the backend returns an HTTP 400 error saying "Field TIME_RANGE is not supported for resource EXECUTION".
The key problem seems to be in the
QueryFilterUtils- specificallyTimeLineSearch.extractFrom()which only looks at top-level filters, not recursive children of conditional groups. And thereplaceTimeRangeWithComputedDateFiltermethod similarly only handles top-level filters.Let me look at the execution controller to see how filters are processed:
- Assistant
Let me look at the frontend code to understand what filters are sent for the executions view:
- Assistant
Let me look at the frontend code to understand how filters are sent for the executions view:
- Assistant
Let me look at the timeRangeQuery.ts to understand how TIME_RANGE is used:
- Assistant
Let me look at the execution controller to see the order of operations for filters:
- Assistant
Now I see the issue. The
TimeLineSearch.extractFrommethod only looks at top-level filters (line 28-38), but when a conditional group is used, theTIME_RANGEfilter may be nested inside children. Similarly,updateFiltersandupdateFiltersForEndDateonly map over top-level filters, not recursing into children.Let me also check the
replaceTimeRangeWithComputedDateFiltermethod's usage with theextractFrom: - Assistant
Let me now understand the frontend side better to see what happens when a conditional group is added:
- Assistant
Now let me understand the issue better. Let me look at the
useFilterGroupsto understand the tree structure: - Assistant
Now I understand the issue. Let me look at how the filters are validated:
- Assistant
The validateQueryFilters isn't directly called in the ExecutionController. Let me find where validation happens.
- Assistant
Let me look at the AbstractJdbcRepository where validation happens:
- Assistant
Now I understand the issue. The
TimeLineSearch.extractFrommethod only looks at top-level filters. When the UI adds a conditional group, theTIME_RANGEfilter is nested inside a child group. Similarly,updateFiltersonly processes top-level filters. Let me look at thetoConditionmethod to understand how conditional groups are handled: - Assistant
Let me understand the full flow. I need to check how filters are parsed from query parameters and when validation happens:
- Assistant
Let me look at the QueryFilterFormat annotation and how filters are parsed:
- Assistant
Let me look at the binder that processes the query filter format:
- Assistant
Let me look at the binder:
- Assistant
Now I understand the full picture. Let me trace through the flow:
- Frontend sends filters which may include a TIME_RANGE filter nested inside a conditional group (AND/OR node)
- In the controller,
replaceTimeRangeWithComputedDateFilter(filters, dateFilter)is called TimeLineSearch.extractFrom(filters)only iterates over top-level filters, missing TIME_RANGE inside childrenupdateFiltersonly maps over top-level filters, so the TIME_RANGE inside children isn't converted to START_DATE- The unchanged filters are passed to the repository, which calls
validateQueryFilters validateQueryFiltersrecursively validates children, finds TIME_RANGE, and reports it's not supported for EXECUTION
The fix is to make
TimeLineSearch.extractFromand theupdateFilters/updateFiltersForEndDatemethods recurse into conditional group children.Let me look at the existing test file for this:
- Assistant
Now I have a clear understanding of the issue. Let me trace through the flow:
- When the user adds a conditional group (AND/OR node) with filters, the
TIME_RANGEfilter is nested inside the children of a node filter TimeLineSearch.extractFrom()only iterates over top-level filters, missingTIME_RANGEinside childrenupdateFilters()only maps over top-level filters, so theTIME_RANGEinside children isn't converted toSTART_DATEvalidateQueryFilters()recursively validates children, findsTIME_RANGE, and reports it's not supported forEXECUTION
The fix is to make
TimeLineSearch.extractFrom()and the update methods inQueryFilterUtilsrecursive.Let me fix the
TimeLineSearchclass first: - When the user adds a conditional group (AND/OR node) with filters, the
- Assistant
I see the problem clearly now. The
TimeLineSearch.extractFrommethod only processes top-level filters. When aTIME_RANGEfilter is inside a conditional group (node), it's not found because the loop only looks atfilter.field()which isnullfor nodes. TheupdateFiltersmethods have the same issue.Let me fix
TimeLineSearch.extractFromto recurse into conditional group children: - Assistant
Let me try with replace command instead:
- Assistant
Let me look at how the frontend encodes filters to understand what gets sent:
- Assistant
Let me look at the
encodeFilterGroupsToQueryfunction to understand how filters are encoded to query params: - Assistant
- Assistant
Now I fully understand the issue! Let me trace through:
- When there are multiple groups (including conditional groups), the prefix changes from
filterstofilters[or][0] - So the
timeRangefilter gets written asfilters[or][0][timeRange][EQUALS](nested inside a conditional group) - The
QueryFilterFormatBinderparses this into a node filter with children TimeLineSearch.extractFromonly looks at top-level filters, but the TIME_RANGE is inside a child nodeupdateFiltersonly maps over top-level filters, so the TIME_RANGE inside children isn't converted to START_DATE- The unmodified filters go to the repository, which calls
validateQueryFilters validateQueryFiltersrecursively finds the TIME_RANGE inside children and reports it's not supported for EXECUTION
Now let me fix
TimeLineSearch.extractFromto recurse into conditional group children: - When there are multiple groups (including conditional groups), the prefix changes from
- Assistant
Let me try a different approach to edit the file:
- Assistant
Now I need to fix
QueryFilterUtilsto handle conditional groups. TheupdateFilters,updateFiltersForEndDate, andrewriteTriggerDateFiltersmethods need to recurse into children: - Assistant
Now I need to update the
updateFiltersandupdateFiltersForEndDatemethods to recursively handle conditional groups. Let me also look atrewriteTriggerDateFilters: - Assistant
Now let me see the rest of the file:
- Assistant
Now I need to update the
updateFilters,updateFiltersForEndDate, andrewriteTriggerDateFiltersmethods to handle conditional groups (nodes). The issue is that these methods only look at top-level filters and need to recurse into children.Let me create the updated file:
- Assistant
Now let me check the
DateUtils.validateTimelineto see if it needs to be updated too: - Assistant
Let me check DateUtils.validateTimeline to see if it handles conditional groups.
- Assistant
Now let me also check if
DateUtils.validateTimelineneeds to handle conditional groups. Looking at how it's called fromreplaceTimeRangeWithComputedDateFilter, it validates the updated filters. After our fix, the updated filters will have the TIME_RANGE replaced but may still have conditional groups. TheDateUtils.validateTimelineonly checks top-level filters. But the main issue is the TIME_RANGE field validation, and thevalidateTimelineis just a secondary check for date ordering. Let me also updateDateUtils.validateTimelineto handle conditional groups:The
DateUtils.validateTimeline(List<QueryFilter> filters)also only processes top-level filters. Let me update it to handle conditional groups too: - Assistant
Let me look at the validateTimeline method in DateUtils:
- Assistant
The
DateUtils.validateTimeline(List<QueryFilter> filters)also needs to handle conditional groups. Let me update it to recurse into children: - Assistant
Now let me verify the changes by running the existing tests. First, let me check the test for
QueryFilterUtilsTest: - Assistant
Let me look at the
TimeLineSearchTest: - Assistant
Now let me also check the
QueryFilterFormatBinderTestfor conditional group tests: - Assistant
Let me check the QueryFilterTest for tests about conditional groups:
- Assistant
Let me look at the test at line 743:
- Assistant
Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
Now let me run the QueryFilterUtilsTest:
- Assistant
Now let me run the QueryFilterFormatBinderTest:
- Assistant
Now let me run the QueryFilterTest:
- Assistant
Now let me also run the AbstractJdbcRepositoryTest:
- Assistant
All tests pass. Now let me create a reproduction script to verify the issue is fixed:
- Assistant
Let me write a test that validates the exact scenario from the issue - simulating the frontend sending
filters[or][0][timeRange][EQUALS]=PT168Handfilters[or][1][labels][EQUALS][foo]=bar: - Assistant
Let me verify my changes by creating a proper test. First, let me look at the full test files to understand the test framework being used:
- Assistant
Now let me verify the changes look correct by looking at the diff:
- Assistant
Let me look at the full diff:
- Assistant
The diff looks clean. Now let me run all the related tests to make sure everything passes:
- Assistant
All 81 tests pass. Now let me also run the core tests:
- Assistant
Let me run the full webserver test suite to make sure nothing is broken:
- Assistant
The full webserver test suite timed out. Let me run just the relevant tests instead:
- Assistant
All 22 tests pass. Let me also run the core DateUtils test to make sure nothing is broken there:
- Assistant
Let me check if there are any other callers of these methods that might be affected:
- Assistant
The diff looks correct. Let me verify one more thing - make sure the
AbstractJdbcRepositorytest also still passes: - Assistant
All tests pass. Let me now verify the complete list of changes and make sure everything is in order:
- Assistant
Let me run one more comprehensive test pass:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.