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 the codebase and locate relevant files related to filters, conditional groups, and the error message about TIME_RANGE. Let's first get an overview.
- Assistant
Let me search for the error message to find the relevant code.
- Assistant
Let me look at the error message and the QueryFilter class to understand the issue.
- Assistant
Let me search for "is not supported for resource" to find the error message.
- Assistant
Let me look at the QueryFilter class to understand the TIME_RANGE field.
- Assistant
Now let me understand the issue. The error says "Field TIME_RANGE is not supported for resource EXECUTION". This suggests there's a validation that checks which fields are supported for which resource types. The issue mentions "conditional groups" - let me look at how conditional groups work in the filter system.
- Assistant
Let me look at the
Resourceenum to see the EXECUTION resource definition and understand the validation flow: - Assistant
Now let me look at how TIME_RANGE is handled in QueryFilterUtils:
- Assistant
Now let me look at the
TimeLineSearchclass to understand how it extracts filters: - Assistant
Now let me look at how filters are validated in the webserver controller for executions:
- Assistant
Let me look for how execution filters are validated - likely in ExecutionController or a service.
- Assistant
Now let me look at the
replaceTimeRangeWithComputedDateFiltermethod and how it handles the filters. The issue seems to be that when a conditional group is used, the method doesn't handle the case where the filter is a node (has children) properly. - Assistant
Let me check the test to see how conditional groups (nodes) are handled in validation:
- Assistant
Let me look at the frontend to understand how conditional groups are structured:
- Assistant
Let me check where the validation is called in the execution flow:
- Assistant
Let me look at the
QueryFilterFormatBinderto understand how filters with conditional groups are parsed: - Assistant
Let me look at the
QueryFilterFormatBinderto understand how filters with conditional groups are parsed. - Assistant
Now I need to understand the flow more clearly. Let me look at how the ExecutionController uses filters:
- Assistant
Let me look at the repository code to see where validation happens and where the error comes from.
- Assistant
Let me look at the full execution search method to understand the flow:
- Assistant
Let me look at the test for QueryFilterUtils to understand the expected behavior:
- Assistant
Now I understand the issue. Let me trace through the problem:
- When a conditional group (node) contains a
TIME_RANGEfilter inside it (e.g.,ORgroup withlabelsfilter), theTimeLineSearch.extractFrom()method only iterates over top-level filters - The
replaceTimeRangeWithComputedDateFilter()method also only processes top-level filters, not recursing into children - The
updateFilters()method doesn't handle children of conditional groups either
Let me verify this understanding by looking at the
validateQueryFiltersmethod more carefully and the error flow: - When a conditional group (node) contains a
- Assistant
Now I understand the issue! The problem is that when conditional groups (nodes with children) are used:
TimeLineSearch.extractFrom()only looks at top-level filters, not recursing into children of conditional groupsQueryFilterUtils.updateFilters()andupdateFiltersForEndDate()only process top-level filters- So when TIME_RANGE is inside a conditional group, it doesn't get resolved to START_DATE, and the validation then rejects it
Let me verify this by checking where TIME_RANGE is expected to be handled and look at the frontend to see what data is being sent:
- Assistant
Let me look at how the ExecutionController calls the repository to understand the full flow:
- Assistant
Now let me understand the
updateFiltersmethod more closely and see if it handles children: - Assistant
Now I understand the problem. When a conditional group (node) contains a TIME_RANGE filter, the
TimeLineSearch.extractFrom()andupdateFilters()methods only look at top-level filters and don't recurse into children of conditional groups. This means TIME_RANGE inside a conditional group never gets resolved to START_DATE/END_DATE, and the validation then rejects it as unsupported for EXECUTION resource.Let me check the existing tests for QueryFilter to see if there's already a test for this case:
- Assistant
Let me look at where the validation happens in the JDBC repository:
- Assistant
Now I have a clear understanding of the issue. Let me trace through what happens with conditional groups:
- Frontend sends:
filters[or][0][timeRange][EQUALS]=PT24H&filters[or][0][labels][EQUALS][foo]=bar - This creates a conditional group node with
TIME_RANGEinside its children replaceTimeRangeWithComputedDateFilter()is called, butTimeLineSearch.extractFrom()andupdateFilters()only iterate top-level filters- The
TIME_RANGEinside the conditional group never gets resolved toSTART_DATE - Repository receives the filters with
TIME_RANGEstill present inside the conditional group validateQueryFilters()recurses into children and findsTIME_RANGE, rejecting it as unsupported forEXECUTION
The fix needs to make
TimeLineSearch.extractFrom()andQueryFilterUtils.updateFilters()handle conditional groups by recursing into children.Let me first check what
toConditiondoes for nodes: - Frontend sends:
- Assistant
Now I understand the issue completely. Let me write a reproduction script first to confirm the issue:
- Assistant
Let me look at the
TimeLineSearch.extractFrommethod more closely to understand how it needs to be made recursive: - Assistant
Now I understand the problem clearly. Let me trace through what happens:
- Frontend sends a conditional group with TIME_RANGE inside (e.g.,
filters[or][0][timeRange][EQUALS]=PT24H&filters[or][0][labels][EQUALS][foo]=bar) - This gets parsed into a QueryFilter node with children containing TIME_RANGE and LABELS
replaceTimeRangeWithComputedDateFilter()callsTimeLineSearch.extractFrom()which only looks at top-level filters, not recursing into children- Since TIME_RANGE is inside the node's children,
extractFrom()doesn't find it and treats it as no time range specified updateFilters()also only processes top-level filters, leaving TIME_RANGE inside the node unchanged- The unresolved filters are passed to the repository
validateQueryFilters()correctly recurses into children and finds TIME_RANGE, which is not in EXECUTION's supported fields- Error is thrown
The fix needs to:
- Make
TimeLineSearch.extractFrom()recursive to find TIME_RANGE inside conditional groups - Make
updateFilters()andupdateFiltersForEndDate()recursive to replace TIME_RANGE inside conditional groups
- Frontend sends a conditional group with TIME_RANGE inside (e.g.,
- Assistant
Now I understand the full picture. The fix needs to make
TimeLineSearch.extractFrom()andQueryFilterUtils.updateFilters()/updateFiltersForEndDate()recursive so they can handle TIME_RANGE inside conditional groups.Let me also check the
rewriteTriggerDateFiltersmethod to see if it has the same issue: - Assistant
Now I understand the issue. The
TimeLineSearch.extractFrom()method only looks at top-level filters and doesn't recurse into children of conditional groups. Similarly,updateFilters()andupdateFiltersForEndDate()don't recurse into children of conditional groups. This means TIME_RANGE inside a conditional group never gets resolved to START_DATE, and validation fails.Let me look at the existing test for conditional groups in QueryFilter:
- Assistant
Now I fully understand the issue. Let me trace through the flow:
- Frontend sends filters with a conditional group containing
TIME_RANGEinside its children replaceTimeRangeWithComputedDateFilter()callsTimeLineSearch.extractFrom()which only looks at top-level filtersupdateFilters()also only processes top-level filters- So
TIME_RANGEinside the conditional group is never replaced withSTART_DATE - Repository validation recurses into children and finds
TIME_RANGE, which is not supported forEXECUTIONresource
The fix needs to make
TimeLineSearch.extractFrom(),updateFilters(), andupdateFiltersForEndDate()recursive to handle children of conditional groups. Let me implement this fix: - Frontend sends filters with a conditional group containing
- Assistant
Now let me fix
TimeLineSearch.extractFromto handle conditional groups (nodes) by recursing into children: - Assistant
Let me use the
editcommand instead. - Assistant
Let me use the edit command to modify the file.
- Assistant
Let me use the
editspecial command to fix theTimeLineSearch.extractFrommethod: - Assistant
The edit seems to have removed the rest of the code. Let me check the full file and fix it:
- Assistant
Let me re-read the original file and make the edit more carefully.
- Assistant
Now let me fix the
extractFrommethod to handle nodes (conditional groups) by recursing into children: - Assistant
Good. Now I need to fix the
QueryFilterUtilsmethods to also handle conditional groups. Let me look at the currentupdateFiltersandupdateFiltersForEndDatemethods: - Assistant
Now I need to fix the
updateFiltersandupdateFiltersForEndDatemethods to recurse into children of conditional groups. Let me fix theupdateFiltersmethod: - Assistant
The edit got messed up. Let me revert and start over:
- Assistant
Let me take a more careful approach. Let me use the
replacecommand to make targeted changes: - Assistant
Now let me use the
replacecommand to fixupdateFilters: - Assistant
Now I need to fix
updateFiltersForEndDatesimilarly: - Assistant
Now I need to fix the
rewriteTriggerDateFiltersmethod too. Let me look at the rest of the file: - Assistant
Now let me fix
rewriteTriggerDateFiltersto handle nodes: - Assistant
Now let me verify the file is complete and correct:
- Assistant
Now let me also check if
DateUtils.validateTimelinehandles nodes properly: - Assistant
Let me also check the
DateUtils.validateTimeline(List<QueryFilter>)method to see if it handles nodes properly, and check how theisStartDateFilteris used there: - Assistant
Now let me think about whether
DateUtils.validateTimelinealso needs fixing. Since it's called afterupdateFiltersalready resolved the filters, it should be fine. But let me also checkisStartDateFilterandisEndDateFiltermethods inDateUtilsto make sure they handle the case where filters have been resolved. Let me also check if the issue is specifically about the frontend sending TIME_RANGE inside a conditional group:Let me look at the frontend to understand how filters are sent when conditional groups are added:
- Assistant
Now let me also look at how the
andOfandtoConditionmethods in the JDBC repository handle nodes - they seem to already handle nodes correctly: - Assistant
Now let me verify that the TimeLineSearch fix is correct by looking at it:
- Assistant
I realize there's a subtle issue with the TimeLineSearch fix. The
extractFrommethod both extracts values AND computes the final startDate. When recursing into children, I'm getting the already-computed startDate which will always be non-null due to the default. Let me fix this by separating the extraction and computation: - Assistant
Wait, I need to reconsider the
TimeLineSearch.extractFromfix. The issue is thatextractFromalways returns a non-nullstartDate(due to the default 8-day fallback), so when recursing into children, we can't distinguish between an explicitly set startDate and the default. Let me rethink this. - Assistant
Let me take a better approach. I'll add a separate
collectRawValuesmethod that recursively collects date-related values from the filter tree without computing defaults: - Assistant
Let me think about this more carefully. The problem is that
extractFromboth extracts raw values AND computes defaults. When recursing into children, the child'sextractFromreturns already-computed values (with defaults), and we can't distinguish between explicitly set values and defaults.Let me add an internal helper method that only collects raw values:
- Assistant
Wait, I need to add the
hasExplicitStartDatefield to the class definition. Let me fix this properly: - Assistant
The class definition got messed up. Let me revert and fix properly:
- Assistant
Let me take a completely different and simpler approach. I'll use a helper method that recursively collects raw date filter values from the filter tree:
- Assistant
Let me write a cleaner version that separates raw value collection from default computation:
- Assistant
Let me revert and write the whole file from scratch:
- Assistant
Let me rewrite the file completely with a clean implementation:
- Assistant
Good. Now let me verify the QueryFilterUtils changes are still in place:
- Assistant
Good, the QueryFilterUtils changes are already in place. Let me verify the current state of both files:
- Assistant
Let me check the full diff to make sure everything is correct:
- Assistant
The diff looks good. Now let me also check if
DateUtils.validateTimelineneeds to be updated to handle nodes properly. Let me look at how it's called: - Assistant
I should also update
DateUtils.validateTimelineto handle nodes properly. Let me fix it: - Assistant
I should also update
DateUtils.validateTimelineto handle nodes properly. Let me fix it: - Assistant
The edit got messed up. Let me revert and try again:
- Assistant
Let me write the whole DateUtils file:
- Assistant
Let me verify the file is correct:
- Assistant
Let me check the full file to see if it's properly formatted:
- Assistant
The file has some leftover code. Let me fix it properly:
- Assistant
Let me look at the original lines 120-145:
- Assistant
OK so lines 120-132 are the validateTimeline method. Let me use the edit command to replace just those lines.
- Assistant
The file still has issues. Let me revert and do it properly:
- Assistant
The issue is the line range includes lines I didn't intend to replace. Let me use a more precise approach:
- Assistant
Let me use sed to make the precise edit:
- Assistant
Let me verify the file is correct now:
- Assistant
I see the method is missing closing braces. Let me fix it:
- Assistant
The
forloop is missing its closing brace and thevalidateTimeline(startDate, endDate);call. Let me fix this: - Assistant
The
editcommand is tricky with the line ranges. Let me be more precise with the edit command. The original method spans lines 120-136. - Assistant
OK, the method is from lines 120-135 (inclusive of the closing brace on 135). Let me replace lines 126-132 (the for loop body):
- Assistant
Let me check if the file is correct now:
- Assistant
The
forloop is still not closed properly. The}for the for loop and thevalidateTimeline(startDate, endDate);call are missing. Let me look more carefully. - Assistant
The file looks correct now. Let me verify the full diff of all changes:
- Assistant
The file looks correct now. Let me verify the full diff:
- Assistant
Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
Let me run the existing tests to verify the changes work correctly:
- Assistant
The TimeLineSearch tests pass. Let me also run the QueryFilterUtils tests:
- Assistant
All existing tests pass. Let me also run the QueryFilter tests:
- Assistant
All tests pass. Let me also run the QueryFilterFormatBinder test:
- Assistant
- Assistant
Let me check and fix the
containsDateFieldmethod: - Assistant
I see a bug! The
containsDateFieldmethod withincludeStartEnd=falseonly checks for TIME_RANGE, but the originalupdateFiltersalso checked for START_DATE. Let me fix this: - Assistant
Good, the fix is correct now. Let me run the tests again to make sure everything still passes:
- Assistant
All tests pass. Let me also run the broader test suite for the related modules:
- Assistant
Let me verify the final state of all three files:
- Assistant
Let me verify the full diff one more time to make sure everything is correct:
- Assistant
All changes look correct. Let me run a broader set of tests to make sure nothing is broken:
- Assistant
Let me run the existing tests in the repository to make sure my changes don't break anything. Let me run the webserver tests related to filters.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.