Skip to content

fix(json): JSON.DEL recursive descent duplicate counting for nested same-key elements #5312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 18, 2025

Conversation

vyavdoshenko
Copy link
Contributor

Fixes: #5259

Issue:
JSON.DEL doc "$..a" was returning 2 instead of 1 when deleting nested objects with the same key name, because both parent and child deletions were counted separately.

Solution:
Added filtering logic to avoid counting child nodes that are automatically deleted when their parent is removed. Only applies to recursive descent deletion operations where one object directly contains another with the same target key.

Testing:

  • A unit test was added
  • Fakeredis test was checked poetry run pytest -s test/test_json/test_json.py -k test_json_delete_with_dollar

@vyavdoshenko vyavdoshenko changed the title fix(json): JSON.DEL recursive descent duplicate counting for nested same-key elements [WIP test fails on CI] fix(json): JSON.DEL recursive descent duplicate counting for nested same-key elements Jun 16, 2025
@vyavdoshenko vyavdoshenko marked this pull request as draft June 16, 2025 15:03
@vyavdoshenko vyavdoshenko self-assigned this Jun 16, 2025
@vyavdoshenko vyavdoshenko changed the title [WIP test fails on CI] fix(json): JSON.DEL recursive descent duplicate counting for nested same-key elements fix(json): JSON.DEL recursive descent duplicate counting for nested same-key elements Jun 16, 2025
@vyavdoshenko vyavdoshenko marked this pull request as ready for review June 16, 2025 18:08
@@ -1261,6 +1261,24 @@ TEST_F(JsonFamilyTest, Del) {

resp = Run({"JSON.GET", "json"});
EXPECT_THAT(resp, ArgType(RespExpr::NIL));

if (absl::GetFlag(FLAGS_jsonpathv2)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please add a test in jsonpath_test.cc as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unit test was added to jsonpath_test.cc

@vyavdoshenko vyavdoshenko requested a review from romange June 17, 2025 15:14
@vyavdoshenko vyavdoshenko requested a review from romange June 18, 2025 12:15
stack.emplace_back(json);

// Collect nodes to delete - but simplified without complex filtering
std::vector<JsonType*> nodes_to_delete;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need nodes_to_delete ? what exactly breaks if you delete during the traversal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

} while (!stack.empty());

// Apply deletions with filtering for recursive descent to avoid parent-child duplication
const PathSegment& terminal_segment = path.back();
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we delete immediately without nodes_to_delete, we won't need all this code below, since if we delete parent first, we won't traverse its children.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it seems, you are exactly right.

@vyavdoshenko vyavdoshenko requested a review from romange June 18, 2025 12:44
@vyavdoshenko vyavdoshenko merged commit 7c0b082 into main Jun 18, 2025
10 checks passed
@vyavdoshenko vyavdoshenko deleted the bobik/json_recursive_del_fix branch June 18, 2025 15:08
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.

bug(json): recursive deletion does not delete all the fields
2 participants