Problem/Motivation
#2968972: Cannot PATCH an entity with dangling references in an ER field only limited validation of fields in JSON API PATCH requests to fields received.
JSON API should do what core REST introduced in #2821077: PATCHing entities validates the entire entity, also unmodified fields, so unmodified fields can throw validation errors: limit validation of fields in PATCH requests to fields changed.
Proposed resolution
Wait for #2821077: PATCHing entities validates the entire entity, also unmodified fields, so unmodified fields can throw validation errors to land so that JSON API can reuse core'srest_testtest helper module.- Port all test coverage.
- Port all changes from core REST's
EntityResource& friends.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
wim leersComment #3
gabesulliceTBH, I'd like to wait for an actual bug report about this. I'm not sure this is an actual feature people need.
If you're sending a field, you should expect it to be validated. If you don't intend to change it and you don't want it validated, don't send it.
This could end up being buggy behavior because a valid value for one user could be an invalid value for another, without validated unchanged, sent fields, a server can't ever communicate that to the client.
Comment #4
wim leers#2821077: PATCHing entities validates the entire entity, also unmodified fields, so unmodified fields can throw validation errors landed at last.
I strongly disagree with this. I don't think this is an artificial use case.
It's perfectly reasonable for people to
GETa resource, modify some data, then resubmit it usingPATCH. Any data that is unmodified should not be validated again, per the robustness principle.The irony is that we actually already implemented this by now because people reported this to be an actual problem! See #2968972: Cannot PATCH an entity with dangling references in an ER field.
AFAICT this is now merely a matter of porting #2979945: Port #2821077 to JSON API: limit validation of fields in PATCH requests to fields *changed*'s test coverage.
Comment #5
gabesulliceI don't believe that we did. As the IS says, what we did is only validate the entity fields for those fields included in the request document. We do not currently check if the field has been modified.
I think I still feel like I did in #3. I think that because JSON API allows one to omit fields which one does not wish to modify (and this behavior is defined in the spec) that it's okay if our handling of this is different.
Out of curiosity, I decided to test the behavior of a non-decoupled form.
-10.0.With the proposed change of behavior. It becomes impossible to implement that same behavior.
Our current solution allows the frontend developer to choose which UX they prefer based on whether they decide to send an unmodified field or not.
Comment #6
wim leersYou're right. #2968972: Cannot PATCH an entity with dangling references in an ER field modified JSON API to only validate received fields, not only modified fields.
rest.moduledoes this too.Fair.
Considering this working as designed!