Adding a diff comment to an image will sometimes result in a 422 response
Summary
Adding a comment to an image in the diff view will sometimes result in a 422 Unprocessable Entity
response, with the response body containing the error must be a valid json schema
.
If you view the request that got a 422 response in your browsers developer console, right click and go to Copy >> Copy as cURL you can easily reproduce this.
The issue lies with the x
and y
positional coordinates we pass. On the requests that fail, one of these values will be a decimal. For example, here's the data that was passed to one of my failing requests:
'{"line_type":"old","merge_request_diff_head_sha":"716f5292cbcc68e144e50fbc4114c9a7a1488176","in_reply_to_discussion_id":"","note_project_id":"","target_type":"merge_request","target_id":133095735,"return_discussion":true,"note":{"note":"test","position":"{\"base_sha\":\"fcf0efd9fb4d950a78de10111587925c02c1b233\",\"start_sha\":\"fcf0efd9fb4d950a78de10111587925c02c1b233\",\"head_sha\":\"716f5292cbcc68e144e50fbc4114c9a7a1488176\",\"old_path\":\"nice.jpg\",\"new_path\":\"nice.jpg\",\"position_type\":\"image\",\"old_line\":null,\"new_line\":null,\"x\":219,\"y\":218.00000000000003,\"width\":400,\"height\":400}","noteable_type":"MergeRequest","noteable_id":133095735,"commit_id":null,"type":"DiffNote","line_code":null}}'
Note the value of y
above - it is 218.00000000000003
. I did some testing by editing this value and resending the request, and it seems this occurs anytime the decimal is a non-repeating number. For example, 218.00000000000003
and 218.01
fail, but 218.0000000000000
and 218.00
result in a successful request.
Steps to reproduce
- Create new project with just README.md
- Web IDE -> upload image -> commit & create new branch & MR
- View changes (/diffs) in MR
- Click anywhere on image, type something into comment box
- Click "add comment now" not "Start a review"
- Sometimes doesn't work, message in UI says "Saving the comment failed", 422 error in browser console
What is the current bug behavior?
Adding a comment to an image in the diff view will sometimes result in a 422 Unprocessable Entity
response, with the response body containing the error must be a valid json schema
.
What is the expected correct behavior?
Comment is added to the image diff as expected.
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com.
Possible fixes
It looks like this is occurring here. Perhaps we should just be rounding these numbers down/not grabbing decimal values at all.