Skip to content

[LFXV2-1141] Fix count endpoint ignoring parent filter#34

Merged
asithade merged 1 commit intomainfrom
adesilva/fix-count-parent-filter
Feb 22, 2026
Merged

[LFXV2-1141] Fix count endpoint ignoring parent filter#34
asithade merged 1 commit intomainfrom
adesilva/fix-count-parent-filter

Conversation

@asithade
Copy link
Contributor

@asithade asithade commented Feb 22, 2026

Summary

  • Fix count endpoint (/query/resources/count) ignoring the parent query parameter — both payloadToCountPublicCriteria and payloadToCountAggregationCriteria were setting criteria.ParentRef instead of criteria.Parent, which the OpenSearch template never reads
  • Bump chart version 0.4.110.4.12
  • Fix pre-existing lint errors: SA9003 (empty else branch), SA1029 (string context key) x2

JIRA

LFXV2-1141

The count converters used criteria.ParentRef instead of criteria.Parent,
causing the OpenSearch template to skip the parent_refs term query.

Also fixes pre-existing lint errors (SA9003, SA1029) and bumps chart
version to 0.4.12.

Signed-off-by: Asitha de Silva <asithade@gmail.com>
Copilot AI review requested due to automatic review settings February 22, 2026 19:21
@asithade asithade requested a review from a team as a code owner February 22, 2026 19:21
@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

Walkthrough

This pull request updates the chart version to 0.4.12, corrects field usage from ParentRef to Parent in converter functions, and introduces typed context keys in test files for improved type safety. An unnecessary else branch is also removed from a test.

Changes

Cohort / File(s) Summary
Chart Version Update
charts/lfx-v2-query-service/Chart.yaml
Version bumped from 0.4.11 to 0.4.12.
Field Usage Correction
cmd/service/converters.go
Updated field assignments in payloadToCountPublicCriteria and payloadToCountAggregationCriteria from criteria.ParentRef to criteria.Parent, aligning with the corrected model field name.
Typed Context Keys
cmd/service/error_test.go, pkg/paging/codec_test.go
Added testContextKey type alias in test files and updated context value assignments to use typed keys instead of plain strings, improving type safety in tests.
Test Cleanup
internal/service/resource_search_test.go
Removed empty else branch from cache control assertion block.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing the count endpoint's parent filter issue, which directly addresses the primary bug fix in the changeset.
Description check ✅ Passed The description is directly related to the changeset, providing clear context for all modifications including the parent filter fix, chart version bump, and lint error corrections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch adesilva/fix-count-parent-filter

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes /query/resources/count incorrectly ignoring the parent query parameter by mapping it to the SearchCriteria.Parent field that the OpenSearch template actually consumes, plus a small chart bump and lint-driven test cleanups.

Changes:

  • Fix parent filtering for count requests by setting criteria.Parent (instead of the unused criteria.ParentRef) in both count criteria builders.
  • Bump Helm chart version 0.4.110.4.12.
  • Address lint issues in tests (typed context keys, remove empty else branch).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/service/converters.go Correctly maps payload.Parent to SearchCriteria.Parent for count queries so OpenSearch applies the parent filter.
charts/lfx-v2-query-service/Chart.yaml Chart version bump to reflect the fix release.
pkg/paging/codec_test.go Replaces string context keys with a typed key to satisfy staticcheck.
cmd/service/error_test.go Same typed context key adjustment for staticcheck.
internal/service/resource_search_test.go Removes an empty else branch to satisfy staticcheck without changing behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 214 to 218
criteria.ResourceType = payload.Type
}
if payload.Parent != nil {
criteria.ParentRef = payload.Parent
criteria.Parent = payload.Parent
}
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug fix here (mapping payload.Parent to criteria.Parent) isn’t currently guarded by a test that would have failed before this change. The existing QueryResourcesCount tests cover a parent payload but the mocks return a fixed response and don’t assert on the criteria/query, so a regression back to ParentRef would still pass. Consider adding an assertion (e.g., by having the mock searcher record the received criteria or by rendering the OpenSearch query and checking it includes the parent_refs term) so the parent filter behavior is verified end-to-end for /query/resources/count.

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/service/converters.go (1)

190-251: Consider extracting common filter/date parsing logic.

Both payloadToCountPublicCriteria and payloadToCountAggregationCriteria share significant duplicate code for parsing filters, setting common criteria fields (Tags, TagsAll, Name, Type, Parent), and handling date filtering. Consider extracting this into a shared helper to reduce duplication.

♻️ Example helper extraction
// applyCountPayloadToCriteria sets common fields from QueryResourcesCountPayload to criteria
func applyCountPayloadToCriteria(criteria *model.SearchCriteria, payload *querysvc.QueryResourcesCountPayload) error {
    filters, err := parseFilters(payload.Filters)
    if err != nil {
        return fmt.Errorf("invalid filters: %w", err)
    }
    
    criteria.Tags = payload.Tags
    criteria.TagsAll = payload.TagsAll
    criteria.Filters = filters
    criteria.Name = payload.Name
    criteria.ResourceType = payload.Type
    criteria.Parent = payload.Parent
    
    // Date filtering validation and parsing...
    // (extract the date handling logic here)
    
    return nil
}

Then both functions would call this helper after setting their specific fields (PublicOnly/PrivateOnly, PageSize, GroupBy).

Also applies to: 253-317

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/service/converters.go` around lines 190 - 251,
payloadToCountPublicCriteria and payloadToCountAggregationCriteria duplicate
filter/date parsing and common field assignments; extract that shared logic into
a helper (e.g., applyCountPayloadToCriteria(criteria *model.SearchCriteria,
payload *querysvc.QueryResourcesCountPayload) error) that runs parseFilters,
assigns Tags/TagsAll/Name/ResourceType/Parent, validates date_field presence
when DateFrom/DateTo are used, prefixes DateField with "data.", and calls
parseDateFilter for DateFrom/DateTo, returning any formatted errors; then
simplify both payloadToCountPublicCriteria and payloadToCountAggregationCriteria
to set their specific fields (PublicOnly/PrivateOnly, PageSize,
GroupBy/GroupBySize) and call the new helper to populate the rest.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/service/converters.go`:
- Around line 190-251: payloadToCountPublicCriteria and
payloadToCountAggregationCriteria duplicate filter/date parsing and common field
assignments; extract that shared logic into a helper (e.g.,
applyCountPayloadToCriteria(criteria *model.SearchCriteria, payload
*querysvc.QueryResourcesCountPayload) error) that runs parseFilters, assigns
Tags/TagsAll/Name/ResourceType/Parent, validates date_field presence when
DateFrom/DateTo are used, prefixes DateField with "data.", and calls
parseDateFilter for DateFrom/DateTo, returning any formatted errors; then
simplify both payloadToCountPublicCriteria and payloadToCountAggregationCriteria
to set their specific fields (PublicOnly/PrivateOnly, PageSize,
GroupBy/GroupBySize) and call the new helper to populate the rest.

@asithade asithade merged commit 9e66277 into main Feb 22, 2026
9 checks passed
@asithade asithade deleted the adesilva/fix-count-parent-filter branch February 22, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants