fix(filter): correct deep nested field validation in delete operations #2768
+172
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes incorrect document deletion when using deep nested field filters
(e.g.
main.items.{status: active && price: <100}).Root Cause
validate_object_filter()insrc/filter_result_iterator.cpphas two code paths:is_filter_result_initializedis true)The batched path correctly used
get_nested_field_doc()to traverse deepnested JSON structures.
However, the non-batched path accessed:
document[filter_node->object_field_name]
This fails for multi-level paths such as
main.items, because it attemptsto look up the literal key instead of navigating:
main → items
As a result, nested filters could match incorrectly, leading to unintended
document deletions.
Solution
Updated the non-batched path to use
get_nested_field_doc(), making itconsistent with the batched implementation.
Before
for (const auto& nested_object: document[filter_node->object_field_name])
After
const auto& doc = get_nested_field_doc(filter_node->object_field_name, document);
for (const auto& nested_object: doc)
Files Changed
src/filter_result_iterator.cpp
→ Use get_nested_field_doc() in non-batched validation path (1-line fix)
test/core_api_utils_test.cpp
→ Added two test cases covering nested and deep-nested delete filters
Test Plan
Added:
Both tests verify:
Run tests:
bazel test //:typesense-test --test_filter="CoreAPIUtilsTest.DeleteDocumentsWithNestedFieldFilter"
bazel test //:typesense-test --test_filter="CoreAPIUtilsTest.DeleteDocumentsWithDeepNestedFieldFilter"
Or full suite:
bazel test //:typesense-test
Checklist
Closes #2765