Skip to content

fix(datastore): keep existing query in add_must_sub_query - #9

Merged
adamsrnmsu merged 1 commit into
sandialabs:mainfrom
adamsrnmsu:fix-add-must-sub-query-keeps-query
Nov 18, 2026
Merged

adamsrnmsu merged 1 commit into
sandialabs:mainfrom
adamsrnmsu:fix-add-must-sub-query-keeps-query

Conversation

@adamsrnmsu

Copy link
Copy Markdown
Collaborator

Description

datastore/query_api.py add_must_sub_query(query, sub_query) silently discarded the caller's query when it was not a bool query: if "bool" not in query: query = {"bool": {}}. A caller passing {"match": ...} got back only the sub query, with its own filter gone. pull() wraps the query first, so it was not affected; direct callers were.

Fix: a non-empty non-bool query is wrapped into bool.must, the same way add_filter in the same file does it. An empty query and an existing bool query behave as before.

Related Issues/PRs

Type of Change

  • Bugfix (fix)
  • Feature (feat)
  • Documentation (docs)
  • Refactor (refactor)
  • Chore (CI, build, dependencies, etc.) (chore)
  • Other (please describe):

Checklist

Testing

  • New tests/test_query_api_must_sub_query.py: existing bool query (and the input is not mutated), non-bool query preserved alongside the sub query, empty query. The non-bool test fails on main and passes with the fix.
  • Full suite on macOS without an Elasticsearch server: the same 21 failures and 1 error as main and no new ones (Elasticsearch tests that need a server, plus the macOS-only test_build_paths_uses_var_lib_for_manifest_state).

🤖 Generated with Claude Code

add_must_sub_query silently discarded the caller's query when it was
not a bool query: it replaced it with an empty bool and only added the
sub query. Direct callers (anything not going through pull(), which
wraps the query first) lost their match/term filter.

Root cause: the "bool" not in query branch did query = {"bool": {}}
instead of wrapping the existing query. The fix wraps a non-empty
non-bool query into bool.must, the same way add_filter in this file
does. An empty query and an existing bool query behave as before.

Verified:
- new test_non_bool_query_is_preserved_alongside_sub_query fails on
  main (query dropped) and passes with the fix; the existing-bool and
  empty-query tests pass on both
- full pytest: the same 21 failures and 1 error as main and nothing
  new (Elasticsearch tests with no server running, plus the known
  macOS-only test_build_paths_uses_var_lib_for_manifest_state)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adamsrnmsu
adamsrnmsu merged commit 6f3f427 into sandialabs:main Nov 18, 2026
4 checks passed
@adamsrnmsu
adamsrnmsu deleted the fix-add-must-sub-query-keeps-query branch November 18, 2026 22:45
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.

2 participants