Issue Loading Merge Requests after upgrade from 8.6.9 to 10.4.1

Gitlab version 10.4.1 be80a97 /w Omnibus

It’s 1:20 pm right now and it’s telling me “Upgrade ASAP”, whereas at 1:00 am when I upgraded the software it said “Upgrade Available”. This must be kind of a more intense release cycle than I realized.

So I ran through the upgrade process moving to version 9 and making sure to upgrade the postgres database while the option was available to me, and moving up to 10, and everything seemed good, testing went well, all the self-checks pass. However this morning a developer mentioned to me that merge requests aren’t working and that it either looks like the most recent merge requests or only open merge requests won’t display and throw a 500 instead. Currently, there are newer merge requests and this one has since been closed via the API and still remains inaccessible. I’m not 100% sure how or why and I’m not very familiar with Ruby or the Rails Console or I could probably dive a lot deeper into this on my own.

What it looks like to me is somehow the merge request record is of the type nil:NilClass, and this is missing certain methods which are required for rendering it, or perhaps the discussion is the nil:NilClass and truncated_diff_lines calls something like “self.index”. I’m about to dive into the code more and see if I can’t learn anything else. I just thought I’d post this in case anyone else is interested and might want to help out.

Started GET "/namespace/project/merge_requests/27" for at 2018-02-13 11:25:37 -0600
Processing by Projects::MergeRequestsController#show as HTML
  Parameters: {"namespace_id"=>"namespace", "project_id"=>"project", "id"=>"27"}
Completed 500 Internal Server Error in 813ms (ActiveRecord: 18.9ms)

ActionView::Template::Error (undefined method `index' for nil:NilClass):
    11:   - if diff_file.text?
    12:     .diff-content.code.js-syntax-highlight
    13:       %table
    14:         = render partial: "projects/diffs/line",
    15:           collection: discussion.truncated_diff_lines,
    16:           as: :line,
    17:           locals: { diff_file: diff_file,
  app/models/concerns/discussion_on_diff.rb:42:in `truncated_diff_lines'
  app/views/discussions/_diff_with_notes.html.haml:14:in `_app_views_discussions__diff_with_notes_html_haml__2541579147853832969_70332770350640'
  app/views/discussions/_discussion.html.haml:52:in `_app_views_discussions__discussion_html_haml__147138958233681318_70332737993620'
  app/views/shared/notes/_notes.html.haml:6:in `block in _app_views_shared_notes__notes_html_haml__1358447167243426372_70332750512860'
  app/views/shared/notes/_notes.html.haml:2:in `each'
  app/views/shared/notes/_notes.html.haml:2:in `_app_views_shared_notes__notes_html_haml__1358447167243426372_70332750512860'
  app/views/shared/notes/_notes_with_form.html.haml:5:in `_app_views_shared_notes__notes_with_form_html_haml___2794887440998542403_70332728153840'
  app/views/projects/merge_requests/_discussion.html.haml:11:in `_app_views_projects_merge_requests__discussion_html_haml___3467320002701473927_70332717775080'
  app/views/projects/merge_requests/show.html.haml:79:in `_app_views_projects_merge_requests_show_html_haml___1740311094332364546_70332941567660'
  app/controllers/projects/merge_requests_controller.rb:54:in `block (3 levels) in show'
  lib/gitlab/gitaly_client.rb:274:in `allow_n_plus_1_calls'
  app/controllers/projects/merge_requests_controller.rb:53:in `block (2 levels) in show'
  app/controllers/projects/merge_requests_controller.rb:37:in `show'
  lib/gitlab/i18n.rb:47:in `with_locale'
  lib/gitlab/i18n.rb:53:in `with_user_locale'
  app/controllers/application_controller.rb:324:in `set_locale'
  lib/gitlab/middleware/multipart.rb:93:in `call'
  lib/gitlab/request_profiler/middleware.rb:14:in `call'
  lib/gitlab/middleware/go.rb:18:in `call'
  lib/gitlab/etag_caching/middleware.rb:11:in `call'
  lib/gitlab/middleware/read_only.rb:31:in `call'
  lib/gitlab/request_context.rb:18:in `call'
  lib/gitlab/metrics/requests_rack_middleware.rb:27:in `call'

Traced this a little bit further and actually opened up the file (app/models/concerns/discussion_on_diff.rb:42:in `truncated_diff_lines’) to take a peek, this mostly reinforced the idea that I’m not a Ruby expert. This is the line where the call to .index is throwing an error because diff_line is null somehow.

initial_line_index = [diff_line.index - NUMBER_OF_TRUNCATED_DIFF_LINES + 1, 0].max

I don’t really understand the included do delegate syntax beyond that someone explained to me when you delegate a name to something, in this file to: :first_note, then the delegated calls are passed to that. So when the call to diff_line.index is being made, something like :first_note.index is actually happening. That’s about the extend of my ability to trace the issue back further without any handholding from someone who knows more or perhaps spending quite a while studying the rails framework.

I’ve since opened this issue on the gitlab-ce/libre tracker
I’ve also discovered some code changes addressing the 500 responses.

Right now I’m hoping there’s something I can type into the rails console to get an array of everything which has a LegacyDiffNote, I’ve also asked about this on the relevant commit.