Internal server error when viewing merge request page after fast-forward merge

Preface

This issue originally appeared on the CE issue tracker. After further testing, I've been unable to reproduce this on our CE instance, and I therefore decided to move this issue in the EE issue tracker. For reference, the issue was gitlab-org/gitlab-ce#42367.

Summary

Since we operate according to strict conventions in our projects, our projects' history is (almost) always linear. As such, we decided to try out, on a smaller project, a different workflow, and to only employ fast-forward merge when merging changes into stable branches and the master branch.

After a fast-forward merge, the page of the merge request with was closed triggers an Internal Server Error when one tries to view it.

Steps to reproduce

We are currently employing the EES edition of GitLab. The bug was triggered on the EES. I'm not able to reproduce this on GitLab.com for some reasons, I suppose due to the fact that I don't have access to EE features there :)

Anyway, what we did was simply:

  1. Take a project.
  2. Create a new branch from master and do some simple changes (e.g.: add a file).
  3. Push it online.
  4. Open a merge request from the branch to the master branch.
  5. Merge using git merge --ff-only my-branch-name.
  6. View the merge request page, which should display a server error.

Example Project

I reproduced the workflow which led to the bug in this project. The bug triggered under version 10.4.0, updated on 01/23/2018.

What is the current bug behavior?

Currently, on our instance, the merge request page displays a 500 error.

Looking at log lines in .../gitlab-rails/production.log, a TemplateError appears. Relevant (I hope) log lines and stacktrace follow! Anonymized content is reported in caps lock.

What is the expected correct behavior?

The merge request page should display correctly, as in popeio/merge-request-fast-forward-error!1.

Relevant logs and/or screenshots

Not providing screenshots as the output is a simple 500 error page.

Started GET "/MY/PROJECT/NAMESPACE/merge_requests/1" for MY.GITLAB.IP.ADDRESS at TIMESTAMP
Processing by Projects::MergeRequestsController#show as HTML
  Parameters: {"namespace_id"=>"MY/PROJECT", "project_id"=>"NAMESPACE", "id"=>"1"}
Completed 500 Internal Server Error in 706ms (ActiveRecord: 25.6ms | Elasticsearch: 0.0ms)

ActionView::Template::Error (undefined method `merged_by_id' for #<MergeRequest::Metrics:IDENTIFIER>
Did you mean?  merged_by
               merged_by=):
    21:     -# haml-lint:disable InlineJavaScript
    22:     :javascript
    23:       window.gl = window.gl || {};
    24:       window.gl.mrWidgetData = #{serialize_issuable(@merge_request, serializer: 'widget')}
    25: 
    26:       // Append static, server-generated data not included in merge request entity (EE-Only)
    27:       // Object.assign would be useful here, but it blows up Phantom.js in tests
  app/serializers/merge_request_widget_entity.rb:220:in `build_metrics'
  app/serializers/merge_request_widget_entity.rb:40:in `block in <class:MergeRequestWidgetEntity>'
  app/serializers/base_serializer.rb:14:in `represent'
  app/serializers/merge_request_serializer.rb:14:in `represent'
  app/helpers/issuables_helper.rb:45:in `serialize_issuable'
  app/views/projects/merge_requests/show.html.haml:24:in `_app_views_projects_merge_requests_show_html_haml___4428642733781444069_70099305948260'
  app/controllers/projects/merge_requests_controller.rb:56: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:55:in `block (2 levels) in show'
  app/controllers/projects/merge_requests_controller.rb:39:in `show'
  lib/gitlab/i18n.rb:47:in `with_locale'
  lib/gitlab/i18n.rb:53:in `with_user_locale'
  app/controllers/application_controller.rb:332:in `set_locale'
  lib/gitlab/middleware/multipart.rb:93:in `call'
  lib/gitlab/request_profiler/middleware.rb:14:in `call'
  lib/gitlab/jira/middleware.rb:15:in `call'
  lib/gitlab/middleware/go.rb:18:in `call'
  lib/gitlab/etag_caching/middleware.rb:11:in `call'
  lib/gitlab/middleware/rails_queue_duration.rb:22:in `call'
  lib/gitlab/metrics/rack_middleware.rb:15:in `block 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'

Output of checks

This does not seem to happen on GitLab.com, but I don't have an enterprise account here, so I'm not sure whether this should reproduce on GitLab.com in the first place!

Results of GitLab environment info

Expand for output related to GitLab environment info

System information
System:         Debian 9.3
Proxy:          no
Current User:   git
Using RVM:      no
Ruby Version:   2.3.6p384
Gem Version:    2.6.13
Bundler Version:1.13.7
Rake Version:   12.3.0
Redis Version:  3.2.11
Git Version:    2.14.3
Sidekiq Version:5.0.5
Go Version:     unknown
GitLab information
Version:        10.4.0-ee
Revision:       00592f0
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     postgresql
DB Version:     9.6.5
URL:            https://OUR.GITLAB.HOST.NAME
HTTP Clone URL: https://OUR.GITLAB.HOST.NAME/some-group/some-project.git
SSH Clone URL:  git@OUR.GITLAB.HOST.NAME:some-group/some-project.git
Elasticsearch:  no
Geo:            no
Using LDAP:     no
Using Omniauth: no
GitLab Shell
Version:        5.11.0
Repository storage paths:

default:      /var/opt/gitlab/git-data/repositories
Hooks:          /opt/gitlab/embedded/service/gitlab-shell/hooks
Git:            /opt/gitlab/embedded/bin/git

Results of GitLab application Check

Expand for output related to the GitLab application check

Checking GitLab Shell ...
GitLab Shell version >= 5.11.0 ? ... OK (5.11.0)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
... bunch of "OK" for various repositories, no errors
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
.... Bunch of "yes", only "yes", no errors
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.3.6)
Git version >= 2.7.3 ? ... yes (2.14.3)
Git user has default SSH configuration? ... yes
Active users: ... NUMBER-OF-ACTIVE-USERS
Elasticsearch version 5.1 - 5.5? ... skipped (elasticsearch is disabled)
Checking GitLab ... Finished

Possible fixes

Edited Jan 26, 2018 by Gabriele Peiretti
Assignee Loading
Time tracking Loading