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.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /kestra, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files related to filters, conditional groups, and the error message. Let me first get an overview.
- Assistant
Let me explore the repository structure to understand what we're working with.
- Assistant
Let me look for the error message about "TIME_RANGE is not supported for resource EXECUTION" and the filter-related code.
- Assistant
Let me look at the QueryFilter class and the ExecutionController to understand the filter structure.
- Assistant
Let me understand the issue. The problem is about "conditional groups" in filters. When a user adds a conditional group filter, the backend returns a 400 error saying "Field TIME_RANGE is not supported for resource EXECUTION".
Let me look at the relevant files to understand the query filter structure and the conditional groups.
- Assistant
Let me look at the complete file since it was truncated:
- Assistant
Let me see the full content of the QueryFilter.java file.
- Assistant
Let me continue viewing the file:
- Assistant
Now let me search for how TIME_RANGE is handled and how conditional groups are being processed:
- Assistant
Now let me look at how TIME_RANGE filters are processed in the QueryFilterUtils:
- Assistant
Now I see the issue. The
QueryFilterUtilsprocesses TIME_RANGE filters but only at the top-level (first-level) filters. When a user creates a conditional group (a node filter withlogicalandchildren), the TIME_RANGE inside the children is not being processed.Let me look at the
TimeLineSearch.extractFrommethod to see how it extracts time range filters. - Assistant
Now let me look at the execution controller and how it handles conditional groups:
- Assistant
Let me look at the execution controller to see how it receives the filters and validates them:
- Assistant
Let me look at the full execution controller to understand the flow:
- Assistant
Let me look at the specific area around line 250 where
replaceTimeRangeWithComputedDateFilteris called: - Assistant
Now I understand the issue. Let me look at the validation and how TIME_RANGE is handled in the filter processing:
- Assistant
Let me trace the flow to understand when validation happens. Let me look at the
@QueryFilterFormatannotation: - Assistant
Let me look at the
@QueryFilterFormatannotation and theQueryFilterFormatBinderto understand when validation happens. - Assistant
Now I understand the issue. Let me look at the
replaceTimeRangeWithComputedDateFiltermethod more carefully. The issue is that when conditional groups (nestedQueryFilternodes withlogicalandchildren) are used, theTimeLineSearch.extractFrommethod only processes the top-level filters, not the nested children inside conditional groups. So ifTIME_RANGEis inside a conditional group's children, it won't be processed/converted toSTART_DATE, and it will be passed directly to the repository, which then validates and fails becauseTIME_RANGEis not in the supported fields forEXECUTION.Let me trace through the code:
TimeLineSearch.extractFrom(filters)iterates overfilters(top-level only)- It looks for
START_DATE,END_DATE, andTIME_RANGEfields - If found, it computes a resolved date
- Then
updateFiltersorupdateFiltersForEndDateprocesses the top-level filters again, replacingTIME_RANGE/START_DATE/END_DATEwith computed dates
The problem: if a
TIME_RANGEfilter is nested inside a conditional group (aQueryFilternode withlogicalandchildren), it's NOT found at the top level, so it's NOT processed. Then when the repository validates the filters, the nestedTIME_RANGEfails validation.The fix should be to:
- Make
TimeLineSearch.extractFromtraverse nested children to find TIME_RANGE filters - Make
updateFilters/updateFiltersForEndDate/replaceTimeRangeWithComputedDateFilterproperly handle nested filters
Let me look more carefully at what the UI sends and how the fix should work.
- Assistant
Let me check the QueryFilterFormat annotation to see if validation is done there:
- Assistant
Let me check where
validateQueryFiltersis called: - Assistant
Let me check the AbstractJdbcRepository where validation is called:
- Assistant
Let me look at the
toConditionmethod to see how it handles nested filters: - Assistant
Now I understand the full picture. Let me look at how the
updateFiltersandupdateFiltersForEndDatemethods work. They only look at the top-level filters list, not recursing into nested children.The issue is:
- When a user adds a conditional group filter in the UI, it creates a nested
QueryFilternode withlogicalandchildren - The TIME_RANGE filter might be inside this conditional group
TimeLineSearch.extractFrom(filters)only looks at the top-level filtersQueryFilterUtils.updateFilters/updateFiltersForEndDateonly replace TIME_RANGE at the top level- Then validation is called, which recursively validates children, and finds TIME_RANGE in the nested group, but TIME_RANGE is not in the supported fields for EXECUTION resource
Wait, actually the error says "Field TIME_RANGE is not supported for resource EXECUTION". This means the validation is failing on TIME_RANGE. But looking at the EXECUTION supported fields:
EXECUTION { @Override public List<Field> supportedField() { return List.of( Field.QUERY, Field.SCOPE, Field.FLOW_ID, Field.START_DATE, Field.END_DATE, Field.STATE, Field.LABELS, Field.TRIGGER_EXECUTION_ID, Field.CHILD_FILTER, Field.NAMESPACE, Field.KIND, Field.PARENT_ID ); } },TIME_RANGE is NOT in this list. But it IS supported at the webserver level - the
QueryFilterUtilsconverts TIME_RANGE to START_DATE before passing to the repository. The problem is that when filters are nested in a conditional group, the TIME_RANGE inside the nested children doesn't get converted before validation.So the flow is:
- UI sends filters including nested TIME_RANGE
replaceTimeRangeWithComputedDateFilterconverts top-level TIME_RANGE but misses nested ones- Validation runs on the full tree including nested TIME_RANGE
- TIME_RANGE is not in EXECUTION's supported fields → error
The fix is to either:
- Make the TIME_RANGE replacement recursive (handle nested filters) - this is the right fix
- Or add TIME_RANGE to EXECUTION's supported fields - this would be wrong because TIME_RANGE should be converted to START_DATE before database queries
Let me trace through more carefully how the
replaceTimeRangeWithComputedDateFilterworks:Let me understand the full flow. Let me look at the
replaceTimeRangeWithComputedDateFiltermethod more carefully: - When a user adds a conditional group filter in the UI, it creates a nested
- Assistant
Now I understand the issue. Let me trace the flow:
- The UI sends filter parameters that include a conditional group (e.g., an OR group) containing a TIME_RANGE filter along with other filters like labels.
- The
QueryFilterFormatBinderparses these into aList<QueryFilter>, where some elements might be nodes (withlogicalandchildren) rather than leaves. - In the controller,
QueryFilterUtils.replaceTimeRangeWithComputedDateFilter(filters, dateFilter)is called. - The
TimeLineSearch.extractFrom(filters)method only iterates over the top-level filters list - it doesn't recurse into nested node filters (conditional groups). - Then
updateFiltersalso only maps over the top-level list. - The actual
TIME_RANGEfilter inside the conditional group is NOT replaced. - Then
QueryFilter.validateQueryFiltersis called in thefiltermethod ofAbstractJdbcRepository, and the validation correctly recurses into nested nodes (line 754-756 of QueryFilter.java:if (filter.isNode()) { filter.children().forEach(child -> collectValidationErrors(child, resource, errors)); return; }). - This finds the
TIME_RANGEfield in the nested children and reports it as unsupported.
So the issue is that
TimeLineSearch.extractFrom()and theupdateFilters()/updateFiltersForEndDate()methods don't recurse into nested conditional groups.The fix needs to:
- Make
TimeLineSearch.extractFrom()recurse into nested filters to find TIME_RANGE/START_DATE/END_DATE - Make
updateFilters()andupdateFiltersForEndDate()recurse into nested filters to replace TIME_RANGE/START_DATE with computed dates
Let me look at the code more carefully to implement the fix.
- Assistant
Now I have a clear understanding of the issue. Let me also look at how
DateUtils.validateTimelineworks: - Assistant
Let me look at the DateUtils.validateTimeline:
- Assistant
Let me look at the test files for insight:
- Assistant
Now let me understand the full picture. Let me look at the test file that mentions TIME_RANGE:
- Assistant
Let me look at the UI code to understand how filters are structured:
- Assistant
Let me look at how the frontend structures filters when conditional groups are used:
- Assistant
Let me look at how the frontend structures filters when conditional groups are used. Let me look at the filterGroups composable:
- Assistant
Let me look at how the filters are serialized to understand the URL format:
- Assistant
Let me look at the helpers.ts file to understand how filters are serialized to query parameters.
- Assistant
Now I understand the root cause! Let me look at the
writeFilterfunction in the UI:When
timeRangeis a duration (like "PT168H"), the key is written with the prefix:query[`${prefix}[${key}][${comparatorKey}]`] = value?.toString() ?? ""This means if the filter is inside a conditional group, the URL param would be:
filters[or][0][timeRange][EQUALS]=PT168HThe binder parses this into a
QueryFilternode withlogical=ORcontaining a child withfield=TIME_RANGE. ButreplaceTimeRangeWithComputedDateFilteronly processes top-level filters and doesn't recurse into children of node filters. The TIME_RANGE inside the node remains and validation rejects it because EXECUTION resource doesn't include TIME_RANGE in its supported fields.The fix is to make
TimeLineSearch.extractFrom()andupdateFilters/updateFiltersForEndDaterecursive to handle nested filters. Let me implement this.Now I understand the root cause! The
timeRangefilter gets written inside conditional group prefixes, butreplaceTimeRangeWithComputedDateFilterandTimeLineSearch.extractFromonly process top-level filters. Let me fix this.Let me first look at the existing tests to understand expected behavior:
- Assistant
Now let me understand the full problem flow. Let me look at the memory-based repository implementation:
- Assistant
Now I need to understand the full problem flow. Let me trace it through:
- The user adds a conditional group filter with
ORoperator and a label filter - The UI sends a request with filters that include the TIME_RANGE (from the default quick filter) as part of the URL query params
- The
QueryFilterFormatBinderparses these intoQueryFilterobjects with nodes (conditional groups) and leaves - The
ExecutionController.searchExecutions()callsQueryFilterUtils.replaceTimeRangeWithComputedDateFilter(filters, dateFilter) - This method calls
TimeLineSearch.extractFrom(filters)which only iterates over the top-level filters list - Then it calls
updateFilters(filters, resolvedDate)which also only processes top-level filters - The filters are then passed to the repository which validates them
Wait, let me think again about the actual error. The error says: "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 error comes from
QueryFilter.collectValidationErrors()which is called fromvalidateQueryFilters(). The validation method recurses into children of nodes (line 754-756). So if TIME_RANGE is inside a conditional group node, the validation WOULD find it.But the
replaceTimeRangeWithComputedDateFiltermethod does NOT recurse into children. So here's the problem:- Default filter includes
TIME_RANGEat the top level - User adds a conditional group (which is a node with OR/AND and children)
- The UI sends the TIME_RANGE inside the conditional group OR alongside it
Actually wait, let me re-read the issue more carefully. The issue says:
- "Navigate to the Executions view" (so there are default filters already)
- "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 flow is:
- There are already default filters at the top level (including TIME_RANGE)
- User adds a new conditional group
- Inside the conditional group, user adds labels foo:bar
Looking at the URL encoding:
- Top-level filters would be:
filters[timeRange][EQUALS]=PT168H(default) - The conditional group would be:
filters[or][0][labels][EQUALS][foo]=baror similar
Wait, but looking at the binder pattern
FILTER_PATTERN, let me understand how the URL is structured. The default top-level filters would befilters[timeRange][EQUALS]=PT168H, and the conditional group would befilters[or][0][labels][EQUALS][foo]=bar.These are parsed by the binder into:
[ QueryFilter(field=TIME_RANGE, operation=EQUALS, value="PT168H"), // top-level leaf QueryFilter(logical=OR, children=[ // top-level node (conditional group) QueryFilter(field=LABELS, operation=EQUALS, value={foo: bar}) ]) ]Then
replaceTimeRangeWithComputedDateFilterprocesses the top-level list and finds the TIME_RANGE at the top level, converts it to START_DATE. The OR node with LABELS is left as-is. This should work.But wait, the error says "Field TIME_RANGE is not supported for resource EXECUTION". This means the TIME_RANGE is being validated BEFORE it's replaced. Where is the validation happening?
Looking at the code flow:
- Controller receives filters via
@QueryFilterFormat(Resource.EXECUTION)binder - Controller calls
QueryFilterUtils.replaceTimeRangeWithComputedDateFilter(filters, dateFilter)- this REPLACES TIME_RANGE with START_DATE - The result is passed to the repository
- Repository calls
QueryFilter.validateQueryFilters(filters, resource)- this validates the ALREADY-REPLACED filters
Hmm, but the error says TIME_RANGE is not supported. So either: a) The replacement is NOT happening (TIME_RANGE stays as-is) b) The validation is happening BEFORE the replacement
Let me check if there's another place where validation occurs before the replacement.
Actually, wait. Let me re-read the
@QueryFilterFormatbinder more carefully:public BindingResult<List<QueryFilter>> bind(ArgumentConversionContext<List<QueryFilter>> context, HttpRequest<?> source) { QueryFilter.Resource resource = context.getAnnotationMetadata() .enumValue(QueryFilterFormat.class, QueryFilter.Resource.class) .orElseThrow(() -> new IllegalStateException( "@QueryFilterFormat requires a QueryFilter.Resource value")); int maxDepth = configuration.maxDepthFor(resource); int maxWidth = configuration.maxWidthFor(resource); Map<String, List<String>> queryParams = source.getParameters().asMap(); List<QueryFilter> filters = getQueryFilters(queryParams, maxDepth, maxWidth); return () -> Optional.of(filters); }The binder does NOT validate. It only parses and checks depth/width constraints. So the validation must happen later.
OK so let me think about this differently. Maybe the issue is with the
NODEshape of the conditional group. When the user creates a conditional group in the UI, the TIME_RANGE filter is actually INSIDE the conditional group as a child, not at the top level.Wait, looking at the UI code more carefully:
case "timeRange": { if (typeof value === "object" && "startDate" in value) { query["filters[startDate][GREATER_THAN_OR_EQUAL_TO]"] = value.startDate.toISOString() query["filters[endDate][LESS_THAN_OR_EQUAL_TO]"] = value.endDate.toISOString() } else { query[`${prefix}[${key}][${comparatorKey}]`] = value?.toString() ?? "" }The
prefixdepends on the position in the group structure. If the filter is at the top level (the only leaf group), the prefix is "filters". If it's inside a conditional group, the prefix would be something likefilters[or][0].But wait, the TIME_RANGE is a "quick filter" that's always present. When the user adds a conditional group, does the TIME_RANGE stay at the top level? Let me look at the UI flow more carefully.
Actually, I think the issue might be simpler. Let me re-read the issue:
- User is on Executions view (default filters including TIME_RANGE)
- User adds a new conditional group (OR operator)
- Adds labels foo:bar inside the group
The result is that the filters sent to the server include both:
- The default TIME_RANGE filter at the top level
- A conditional group with LABELS
And the
replaceTimeRangeWithComputedDateFiltershould handle the top-level TIME_RANGE correctly.Unless... the issue is that when adding a conditional group, the TIME_RANGE gets MOVED into the conditional group? Or the UI restructures the filters in a way that moves the TIME_RANGE inside?
Actually, I think I need to look at this from a different angle. Let me look at the
@QueryFilterFormatannotation on the controller to see if the validation error happens during binding.Actually, looking at the
bindmethod again - it doesn't validate. So the error must come from somewhere else.Let me search for where
InvalidQueryFiltersExceptionis thrown or caught. - The user adds a conditional group filter with
- Assistant
Now I need to understand the full picture. Let me trace through what happens when a user adds a conditional group filter with the UI.
- Assistant
Let me also look at the frontend test to confirm the structure:
- Assistant
Now I have a clear understanding of the issue. When a user adds a conditional group (wrapper group) in the UI, the
timeRangefilter gets encoded inside a conditional group prefix likefilters[or][0][timeRange][EQUALS]=PT168H. TheQueryFilterFormatBindercorrectly parses this into aQueryFilternode with children. However, the backend'sTimeLineSearch.extractFrom()andQueryFilterUtils.updateFilters()/updateFiltersForEndDate()only process top-level filters and don't recurse into children of conditional groups (nodes). This meansTIME_RANGEinside a conditional group is never replaced withSTART_DATE, and whenvalidateQueryFiltersrecurses into the children, it findsTIME_RANGEwhich is not in the EXECUTION resource's supported fields.Let me fix the
TimeLineSearch.javaandQueryFilterUtils.javafiles to handle nested filters: - Assistant
Now let me fix
TimeLineSearch.javato recurse into children: - Assistant
Now I need to update the
QueryFilterUtilsto handle nested filters. TheupdateFiltersandupdateFiltersForEndDatemethods need to recurse into children of node filters: - Assistant
Now I need to update
updateFiltersandupdateFiltersForEndDateto handle nested filters. I also need to updaterewriteTriggerDateFilterssimilarly. Let me also checkDateUtils.validateTimelinesince it's also only processing top-level filters: - Assistant
Now I need to update
QueryFilterUtils.java. TheupdateFilters,updateFiltersForEndDate, andrewriteTriggerDateFiltersmethods all need to handle nested conditional groups: - Assistant
Now let me also update
rewriteTriggerDateFiltersto handle nested filters: - Assistant
I need to also update
rewriteTriggerDateFiltersandDateUtils.validateTimelineto handle nested filters: - Assistant
I see there's a duplicate closing brace. Let me fix that:
- Assistant
There's a duplicate closing brace. Let me fix that.
- Assistant
Good, now the
QueryFilterUtilsis fixed. Now let me also updateDateUtils.validateTimelineto handle nested filters: - Assistant
Now let me check if the trigger repository also has similar issues:
- Assistant
Let me check if the trigger repository also needs similar changes:
- Assistant
Now let me also check if there's a memory-based execution repository that might need similar fixes:
- Assistant
Let me now look at the memory-based repository:
- Assistant
Let me check the memory-based execution repository.
- Assistant
Now let me verify the changes compile and run the relevant tests. First, let me check the current state of all modified files:
- Assistant
Let me also verify the QueryFilterUtils file:
- Assistant
Now let me check the DateUtils.java file:
- Assistant
Good. Now let me try to compile the changes and run the relevant tests:
- Assistant
Compilation succeeded (only warnings, no errors). Now let me run the relevant tests:
- Assistant
Hmm, the output doesn't show test results. Let me check if it ran successfully or not.
- Assistant
Let me check the test results:
- Assistant
Let me try a different approach to check the test results:
- Assistant
The tests are up-to-date. Let me force re-run them:
- Assistant
All TimeLineSearch tests pass. Let me run the QueryFilterUtilsTest:
- Assistant
All tests pass. Let me also run the QueryFilterFormatBinderTest:
- Assistant
All tests pass. Now let me create a test to verify the fix works for the specific scenario described in the issue:
- Assistant
Let me run the tests through Gradle instead. Let me look at the JDBC test:
- Assistant
All 81 tests pass. Let me also run the JDBC repository tests that deal with filters:
- Assistant
All tests pass. Let me also run the core repository tests:
- Assistant
The core repository tests are abstract and need a concrete implementation. Let me check for test utility tests:
- Assistant
Let me check if there are H2 tests that test the execution repository with filters:
- Assistant
Now let me also check the
andOfandtoConditionmethods inAbstractJdbcRepositoryto make sure they properly handle the nested conditional groups: - Assistant
Good. The JDBC repository already handles node filters correctly - it recurses into children when building SQL conditions. The issue was that the TIME_RANGE filter inside conditional groups was never being replaced before validation.
Let me now do a final review of all my changes:
- Assistant
The diff looks clean and correct. Let me run a broader set of tests to make sure nothing is broken:
- Assistant
All 96 tests pass. Let me run the JDBC tests too:
- Assistant
All JDBC tests pass. Let me also run the execution controller tests:
- Assistant
All 23 execution controller tests pass, including
badQueryFilters()which tests filter validation. Let me now do a final comprehensive check: - Assistant
That's fine - the full test suite is too large. Let me verify the final state of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →