-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Fix DisplayOptions Serializer to validate display options when updating a column #1297
Conversation
…display options when updating a column
@pavish This PR adds validation for display options when partially updating a column serializer. Based on the sample requests you had mentioned in issue #1228, I am assuming you would be sending empty object even if the column type has the required display options. Can you open a separate PR to address the issue? |
Codecov Report
@@ Coverage Diff @@
## master #1297 +/- ##
==========================================
+ Coverage 93.49% 93.65% +0.15%
==========================================
Files 114 114
Lines 4426 4426
==========================================
+ Hits 4138 4145 +7
+ Misses 288 281 -7
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I do not understand this. While patching a column, I'd send an empty object if the user has not set any display options even if the column allows display options and has required ones. See Kriti's comment here.
Also the sample requests mentioned in #1228 contain values for all the required fields. |
Sorry got confused with issue #1276 scenario 2, please ignore that message. But this PR should solve the invalid state, so now it has to be |
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.
While I do think this change is needed, and the test looks good, I don't understand how this PR fixes #1228 . Can you add some explanation about that to the description for posterity?
@mathemancer #1228 happens due to a bugs that can lead to invalid data being saved, this PR fixes one of the bugs that can cause the error. I updated the description to mention it is related to #1228 rather being a complete fix. I have also updated the description to mention the cause of the issue and how this PR aims to solve it. |
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.
Okay, thanks for the extra explanation.
Related to #1228
When a column is partially updated with an invalid display option, it does not get validated and the request succeeds due to weird behaviour with the DRF serializer which treats nested data as a partial update too, but we completely replace the display options object when saving it, so we end up with a scenario where a required field could be missing. So when the same object is requested by the API, the serializer throws up an error when looking up for the required field in the display options JSON object. This PR fixes it by validating display options during a partial update
Technical Details
During a partial update of a parent serializer, drf calls the nested serializer with
partial
flag even if we haven't explicitly specified it. We consider update to display options as a full update but since DRF takes a partial flag from the parent serializer, the nested display options serializer gets treated as a partial update, so the serializer becomes valid even if a required field is missing. A mixin was used to fix the behaviour for the individual display options serializer but it wasn't applied to the mapping serializer. This PR adds the mixin that fixes the behaviour of the DRF serializer to the mapping serializer.Screenshots
Checklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin