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

✨ Use JSON Merge Patch when doing a partial update on records #352

Merged
merged 4 commits into from
Dec 28, 2023

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Dec 12, 2023

Fixes #351

@Viicos Viicos force-pushed the feature/json-merge-patch branch from 2bcaa2b to 7481d91 Compare December 12, 2023 11:58
src/objects/api/utils.py Outdated Show resolved Hide resolved
Comment on lines 57 to 60
if v is None:
if k in target:
# remove the key/value pair from target
del target[k]

Choose a reason for hiding this comment

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

By looking at the tests, I see that this is the desired behaviour, but I wonder about the case where we want to set a key to a null value (for example if the key is required but can take null values) 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is following the RFC implementation, but I agree when writing this I thought about this use case. So we could maybe deviate from the spec, depending on which use case we cant to be able to achieve

Copy link
Collaborator

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

I have a general question:

The standard https://datatracker.ietf.org/doc/html/rfc7396 explicitly says that it introduces the new content type application/merge-patch+json. In Objects API only application/json content type is supported.
If Objects API starts supporting RFC 7396 behavior, I think it should support its content type.
@joeribekker what do you think?

Comment on lines 133 to 135
if "data" in validated_data:
# Apply JSON Merge Patch for record data
validated_data["data"] = merge_patch(
Copy link
Collaborator

@annashamray annashamray Dec 19, 2023

Choose a reason for hiding this comment

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

It should be

  • -1 level of indentation
  • only for PATCH

src/objects/api/v2/views.py Outdated Show resolved Hide resolved
src/objects/tests/test_merge_patch.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (55fbbee) 94.78% compared to head (13527cd) 94.81%.
Report is 1 commits behind head on master.

❗ Current head 13527cd differs from pull request most recent head cdeb100. Consider uploading reports for the commit cdeb100 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #352      +/-   ##
==========================================
+ Coverage   94.78%   94.81%   +0.02%     
==========================================
  Files         131      133       +2     
  Lines        4543     4568      +25     
==========================================
+ Hits         4306     4331      +25     
  Misses        237      237              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Viicos Viicos force-pushed the feature/json-merge-patch branch from 13527cd to cdeb100 Compare December 27, 2023 11:11
Copy link
Collaborator

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

Looks very nice and neat!

@Viicos Viicos merged commit 0b0fa76 into master Dec 28, 2023
11 checks passed
@Viicos Viicos deleted the feature/json-merge-patch branch December 28, 2023 13:23
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.

Partial update (PATCH) of an object replaces data
4 participants