You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
resp=requests.post('/foo', json={'unchangeable': 'abc'})
assertresp.status_code==200foo_id=resp.json()['id']
resp=requests.patch(f"/foo/{foo_id}", json={'unchangeable': 'changed!'})
assertresp.status_code==400assertresp.json() == {'errors': {'unchangeable': 'This field is unchangeable'}}
resp=requests.patch(f'/foo/{foo_id}', json={'unchangeable': 'abc'})
assertresp.status_code==200# expected the same behavior for put.
Hi @calvin620707. I don't think this is something we'd want to merge into the core framework, as it seems like a fairly niche case with no single correct implementation. e.g., another user might have a different expectation in that an unchangeable field should effectively become read-only for updates, and that including the field in the request body should be invalid.
My recommendation would be to implement this as a validator class, or as a utility function that can be called from the validate_<field> hook. Note that the validator API will change with #6172.
Checklist
master
branch of Django REST framework.Purpose
This is a feature request to add a new option,
changeable
, for fields to decide whether the field is changeable during put/patch.Proposal
Expected behavior
Pseudo code
I can help to send the MR for this feature if the feature is acceptable.
The text was updated successfully, but these errors were encountered: