Skip to content

Unable to create multiline comments

Summary

When commenting on the diff within an MR, you are sometimes unable to make a multiline comment.

Steps to reproduce

I'm not sure what the steps to reproduce this are.

Locally, I tested this on an existing project and existing MR and this worked as expected:

Screen_Shot_2021-02-19_at_2.25.40_PM

I then created a brand new project and MR, and it was not working. You can make several comments on the same MR and it will not work for any of those.

Example Project

Working: andr3/meet.andr3.net!24 (diffs)

Not Working: pedroms/public-project!16 (diffs)

Not Working (GitLab): !53662 (diffs, comment 513264941)

What is the current bug behavior?

Multiline comments aren't consistently working across MRs. The same parameters are getting passed from the frontend, but the backend will not store the line_range attribute. When the data is returned back to the frontend, it's missing the line_range attribute and is shown as a regular comment.

What is the expected correct behavior?

Multiline comments should always be created with a line_range

Relevant logs and/or screenshots

SAMPLE REQUEST (Not working):

Projects::NotesController#create params

{"view"=>"inline", "line_type"=>"old", "merge_request_diff_head_sha"=>"e3c963372a2a84ff1728556cb1b3e7fe6da9b6ff", "in_reply_to_discussion_id"=>"", "note_project_id"=>"", "target_type"=>"merge_request", "target_id"=>"89", "return_discussion"=>true, "note"=>"[FILTERED]", "namespace_id"=>"root", "project_id"=>"multilinecomments"}

I have checked that in this method, we are able to correctly parse the original position and position to be:

position

"{\"base_sha\":\"2e42871d59a16faf8ce48fd78fc77132e3786cc7\",\"start_sha\":\"2e42871d59a16faf8ce48fd78fc77132e3786cc7\",\"head_sha\":\"e3c963372a2a84ff1728556cb1b3e7fe6da9b6ff\",\"old_path\":\"README.md\",\"new_path\":\"README.md\",\"position_type\":\"text\",\"old_line\":null,\"new_line\":6,\"line_range\":{\"start\":{\"line_code\":\"8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_3_5\",\"type\":\"new\",\"old_line\":null,\"new_line\":5},\"end\":{\"line_code\":\"8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_3_6\",\"type\":\"new\",\"old_line\":null,\"new_line\":6}}}"

original_position

{
  "base_sha":"2e42871d59a16faf8ce48fd78fc77132e3786cc7",
  "start_sha":"2e42871d59a16faf8ce48fd78fc77132e3786cc7",
  "head_sha":"e3c963372a2a84ff1728556cb1b3e7fe6da9b6ff",
  "old_path":"README.md",
  "new_path":"README.md",
  "position_type":"text",
  "old_line":null,
  "new_line":6,
  "line_range":{
    "start":{
      "line_code":"8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_3_5",
      "type":"new",
      "old_line":null,
      "new_line":5
    },
    "end":{
      "line_code":"8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_3_6",
      "type":"new",
      "old_line":null,
      "new_line":6
    }
  }
}

position (again?)

{
  "base_sha":"2e42871d59a16faf8ce48fd78fc77132e3786cc7",
  "start_sha":"2e42871d59a16faf8ce48fd78fc77132e3786cc7",
  "head_sha":"8e5d0f2d446d612d5a92a11175a37aa917fe81ce",
  "old_path":"README.md",
  "new_path":"README.md",
  "position_type":"text",
  "old_line":null,
  "new_line":6,
  "line_range":null
}

This last hash has a nil line_range which gets stored on Note as this:

--- !ruby/object:Gitlab::Diff::Position
attributes:
  :base_sha: 2e42871d59a16faf8ce48fd78fc77132e3786cc7
  :start_sha: 2e42871d59a16faf8ce48fd78fc77132e3786cc7
  :head_sha: 8e5d0f2d446d612d5a92a11175a37aa917fe81ce
  :old_path: README.md
  :new_path: README.md
  :position_type: text
  :old_line:
  :new_line: 6
  :line_range:

The question is what omitted the line_range?

Edited by Michelle Gill