-
-
Notifications
You must be signed in to change notification settings - Fork 232
Make autopatch merge-patch work with nullable fields #791
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
Make autopatch merge-patch work with nullable fields #791
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
195cb11 to
b38e79f
Compare
…patch-behavior Leo/led 1075 modify huma autopatch behavior
7621a1c to
167cb85
Compare
|
@betaprior can you maybe describe why this is needed? I've looked at it a couple times now and am struggling to fully understand this PR. It doesn't comply with https://datatracker.ietf.org/doc/html/rfc7386 and seems to set a sentinel value, but I wonder if this would better be handled using a middleware of some sorts or by using a different patch mechanism than JSON Merge-Patch. For example:
I think the JSON Merge-Patch implementation should probably stick to the RFC standard. What do you think? |
|
@danielgtaylor we discussed this in #634. In that thread, you said
That's exactly what this PR implements. Notably, it's not an approach that I originally wanted to take for the exact reason that you mentioned -- I don't love the idea of going against RFC standards, and we experimented with using the shorthand patch format, but at the end decided that sending JSON bodies with Note that the behavior in this PR isn't changing JSON Merge-Patch implementation -- it's provided by the 3rd party library -- but rather mutates the input and the output to the merge patch function so that it results in desired behavior with respect to nulls (i.e., preserving them instead of dropping them); needless to say the non-RFC compliant behavior is disabled by default. If you think this can be done in middleware, could you outline how? The current approach needs the input and output of the patch function, and offhand I don't think it's possible to access in middleware -- unless I suppose the middleware itself somehow intercepts patch requests and provides its own patch implementation. |
|
Going through this again, I see what you are saying about using a middleware. Any other way would be less efficient than doing this right in the patch handler. I think this is alright to merge as an optional extension and it's a well understood concept to use sentinel values with a special meaning. I don't love it but I can see the value, it provides an alternative people can use, and the implementation is clean. Thanks! |
No description provided.