Skip to content
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

fix: json patch throw error when remove null property #15904

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

vietnguyen
Copy link
Contributor

@vietnguyen vietnguyen commented Dec 12, 2023

https://dhis2.atlassian.net/browse/DHIS2-16299

Issue

Problem in JsonPatchManager:
The JsonPatchManager relies on the presence of properties within a JsonNode to validate patch paths. However, our Jackson ObjectMapper does not serialize properties with null values into JsonNode. This leads to an issue where patch paths referencing null properties are incorrectly deemed invalid, despite these properties existing in the original object.

Fix

  • Validate the patch path in JsonpPatchManager before applying the patch operators.
  • Remove the path validation in RemoveOperation and related tests.

Test

Validation Procedure:

  1. Initial Setup:
    Begin by creating a new UserGroup instance where the code property is intentionally set to null.

  2. Patch Request:
    Execute a JSON patch request to update the code property. Use the following curl command:

curl -X PATCH -v http://localhost:9090/api/userGroups/vAvEltyXGbD
-H "Content-Type: application/json-patch+json"
-d '[{ "op": "replace", "path": "/code", "value": "bonthe" }]'
-u admin:district
  1. Outcome Verification:
    Confirm that the code property is correctly updated to "bonthe".

@vietnguyen vietnguyen force-pushed the DHIS2-16299-41 branch 6 times, most recently from b636189 to c357762 Compare December 13, 2023 08:28
Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Merging #15904 (9e4fcc4) into master (905ccae) will increase coverage by 36.02%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #15904       +/-   ##
=============================================
+ Coverage     30.38%   66.41%   +36.02%     
- Complexity    14192    31510    +17318     
=============================================
  Files          3497     3497               
  Lines        130353   130370       +17     
  Branches      15208    15209        +1     
=============================================
+ Hits          39605    86579    +46974     
+ Misses        87182    36695    -50487     
- Partials       3566     7096     +3530     
Flag Coverage Δ
integration 50.37% <100.00%> (?)
integration-h2 32.31% <88.88%> (?)
unit 30.37% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...java/org/hisp/dhis/jsonpatch/JsonPatchManager.java 93.02% <100.00%> (+93.02%) ⬆️
.../jackson/jsonpatch/operations/RemoveOperation.java 80.00% <100.00%> (ø)

... and 2178 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 905ccae...9e4fcc4. Read the comment docs.

Copy link

sonarcloud bot commented Dec 13, 2023

Copy link
Contributor

@david-mackessy david-mackessy left a comment

Choose a reason for hiding this comment

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

lovely

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