-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
PUT does not completely replace object #3648
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
Comments
While this sort of change will highly affect the current behavior, here's an extract from the RFC 5789 defining the PATCH verb:
|
The behaviour you described can be only achieved by using DRF does not in any way limit you to that specific behaviour. Here is how it works:
As you can see, the PUT request and the views have nothing to do with the optional fields. Overwriting the optional fields with default values should be possible if you modify your |
So is the only current implementation of |
@smcoll Yes, partial_update would behave exactly like update, which may seem like a strange request, but IMO the differing behavior of partial_update is not useful (some may argue it is useful in odd circumstances, but that hardly deserves an entire HTTP verb dedicated to it), but in general I don't see point in REQUIRING needless repetition of existing values. So I basically think current PATCH behavior should be slapped onto PUT, and for now PATCH/PUT will do the same thing. But in future it could open up the possibility of doing some cool stuff with PATCH like specifying instruction (increase by 1, append "foo") instead of field values, which could be useful for avoiding race conditions / simultaneous editing issues. |
We're not in a position to modify the behavior of existing APIs in a way like this.
|
@tomchristie Yeah in hindsight this does seem like something I can solve with a third party or custom library. However I will say that I would probably go the opposite route and just get rid of the half-done PUT behavior and make everything optional (on update: PUT / PATCH). Perhaps disabling PATCH in case I later want to handle them in a special way like I was talking about in my last comment. |
Just my two cents, and I got bit by this as well but it might be nice to have some third party library that requires a |
That would be quite a graceful approach, yup. Agreed. I think there's potential for a nicely scoped third party package here, at least as a starting point. |
Currently PUT does not completely replace the object. Optional fields will be left alone, and IMO that is a little strange.
This means that PUT only overwrites data that has been provided, and successfully leaves everything else alone (like a PATCH request), but then it gets mad at you if you don't supply required data. I personally think that not supplying an argument for a field in a PUT request should result in the same thing that you would get by not supplying an argument for a field in a POST request (when creating the object), that is: the default value.
This way we it would be clearly defined that PATCH updates all fields supplied and leaves all other fields alone, and PUT updates ALL fields and leaves none alone.
The text was updated successfully, but these errors were encountered: