Error 500 creating diff note (comment) - hide whitespace mode
Scenario 1 (review): *Steps:* 1. Go to https://gitlab.com/jay_mccure/bug_triage/-/merge_requests/1/diffs?view=parallel#28827ed01984e87b49208380e411ccab758513f8_37_54 2. Change settings to be `Side by side` and do *not* show whitespace (bug can also occur in `inline` mode also. 3. Start a review with a comment on line 54 (right hand side) 4. Finish Review -> Submit review *Actual outcome:* - 500 error occurs from `/publish` - Comment is actually submitted, but it is also pending and the review is still open - Other comments in the review are lost - Deleting the comment that was submitted requires the user to delete the comment AND refresh the page to remove it. Scenario 2 (add comment now): 1. Go to https://gitlab.com/jay_mccure/bug_triage/-/merge_requests/1/diffs?view=parallel#28827ed01984e87b49208380e411ccab758513f8_37_54 2. Change settings to be `Side by side` and do *not* show whitespace 3. Add an immediate comment on line 54 (right hand side) *Actual outcome:* - 500 error occurs from `/notes` - Overview page fails to show diff for comment (see screenshot below) - Deleting the comment that was submitted requires the user to delete the comment AND refresh the page to remove it. ![500comment480](/uploads/aeb5ce8c131d3e3b867683b90dd9cfe1/500comment480.mov) #### Other symptoms 1. The diff for the comment fails to load in the overview page. `Try Again` does nothing. ![Screen_Shot_2022-11-08_at_14.52.26](/uploads/bec740e59dc70f08f6e21270fd1c45ab/Screen_Shot_2022-11-08_at_14.52.26.png) 2. Comments on whitespace can get hidden see: https://gitlab.com/gitlab-org/gitlab/-/issues/800 <details><summary>Request to `/drafts`</summary> ```json { "view": "parallel", "line_type": "old", "merge_request_diff_head_sha": "1e617cd264d281b92eb93e97cc015572a0c6135a", "in_reply_to_discussion_id": "", "note_project_id": "", "target_type": "merge_request", "target_id": 176052042, "return_discussion": true, "draft_note": { "note": "fd", "position": "{\"base_sha\":\"1b35335879ed1f25044ebcde2b50c9fb451a1976\",\"start_sha\":\"1b35335879ed1f25044ebcde2b50c9fb451a1976\",\"head_sha\":\"1e617cd264d281b92eb93e97cc015572a0c6135a\",\"old_path\":\"500_comment_test.rb\",\"new_path\":\"500_comment_test.rb\",\"position_type\":\"text\",\"old_line\":null,\"new_line\":54,\"line_range\":{\"start\":{\"line_code\":\"28827ed01984e87b49208380e411ccab758513f8_37_54\",\"type\":\"new\",\"old_line\":null,\"new_line\":54},\"end\":{\"line_code\":\"28827ed01984e87b49208380e411ccab758513f8_37_54\",\"type\":\"new\",\"old_line\":null,\"new_line\":54}}}", "noteable_type": "MergeRequest", "noteable_id": 176052042, "commit_id": null, "type": "DiffNote", "line_code": "28827ed01984e87b49208380e411ccab758513f8_37_54" } } ``` </details> <details><summary>Response from `/drafts`</summary> ```json { "id": 19738888, "author": { "id": 11809982, "username": "jay_mccure", "name": "Jay McCure", "state": "active", "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/11809982/avatar.png", "status_tooltip_html": null, "show_status": false, "availability": null, "path": "/jay_mccure" }, "merge_request_id": 176052042, "position": { "base_sha": "1b35335879ed1f25044ebcde2b50c9fb451a1976", "start_sha": "1b35335879ed1f25044ebcde2b50c9fb451a1976", "head_sha": "3b17b67d51dfbb19dc27886bb037194739e98c23", "old_path": "500_comment_test.rb", "new_path": "500_comment_test.rb", "position_type": "text", "old_line": 84, "new_line": 54, "line_range": { "start": { "line_code": "28827ed01984e87b49208380e411ccab758513f8_37_54", "type": "new", "old_line": null, "new_line": 54 }, "end": { "line_code": "28827ed01984e87b49208380e411ccab758513f8_37_54", "type": "new", "old_line": null, "new_line": 54 } } }, "line_code": "28827ed01984e87b49208380e411ccab758513f8_37_54", "file_identifier_hash": "6b80226da38a9a0ecf6ac5004b967aa864e1d117", "file_hash": "28827ed01984e87b49208380e411ccab758513f8", "file_path": "500_comment_test.rb", "note": "fd", "note_html": "<p data-sourcepos=\"1:1-1:2\" dir=\"auto\">fd</p>", "references": { "users": [], "commands": "" }, "discussion_id": null, "resolve_discussion": false, "noteable_type": "MergeRequest", "current_user": { "can_edit": true, "can_award_emoji": false, "can_resolve": false } } ``` </details> 3. When using `/submit_review` quick action a confusing error is displayed and the `/submit_review` comment also fails ![Screenshot_2023-01-18_at_11.30.05](/uploads/c4a5683d92d5dfcfb0c9a33b3b211a9b/Screenshot_2023-01-18_at_11.30.05.png) Sentry suspects https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68045. https://sentry.gitlab.net/gitlab/gitlabcom/issues/2765545/?referrer=gitlab_plugin ``` DiffNote::NoteDiffFileCreationError: Failed to find diff line for: spec/lib/release_tools/promotion/status_note_spec.rb, old_line: , new_line: 42 app/models/diff_note.rb:46:in `create_diff_file' raise NoteDiffFileCreationError, DIFF_LINE_NOT_FOUND_MESSAGE % { lib/gitlab/metrics/instrumentation.rb:160:in `block in create_diff_file' .measure { super } lib/gitlab/metrics/method_call.rb:27:in `measure' retval = yield lib/gitlab/metrics/instrumentation.rb:160:in `create_diff_file' .measure { super } config/initializers/forbid_sidekiq_in_transactions.rb:52:in `block in committed!' Sidekiq::Worker.skipping_transaction_check { super } ... (179 additional frame(s) were not displayed) ``` ## Proposal This issue tracks the mitigation of the data loss caused in this scenario. We'll go ahead with: * Disabling adding comments when seeing the diff with Show whitespace changes turned off. We'll have a follow-up issue to add support for commenting in this diff mode: https://gitlab.com/gitlab-org/gitlab/-/issues/398186
issue