Error 500 creating merge requests

Summary

An Error 500 occurs when creating a merge request. (Using Gitlab 10.2.1)

Steps to reproduce

  • Create a merge request
  • Click on the submit button
  • Error 500

Example Project

Tested on gitlab.com but NOT reproduced

What is the current bug behavior?

An error 500 is blocking the MR creation

What is the expected correct behavior?

No error should block the MR creation

Relevant logs and/or screenshots

/var/log/gitlab/gitlab-rails/production.log

Started POST "/obfuscated/obfuscated/merge_requests" for 192.168.1.obfuscated at 2017-11-23 09:16:15 +0100
Started PATCH "/api/v4/jobs/119401/trace" for 192.168.1.obfuscated at 2017-11-23 09:16:15 +0100
Processing by Projects::MergeRequests::CreationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "merge_request"=>{"title"=>"WIP: obfuscated", "description"=>"", "assignee_id"=>"", "label_ids"=>[""], "force_remove_source_branch"=>"0", "lock_version"=>"", "source_project_id"=>"255", "sourc
e_branch"=>"obfuscated", "target_project_id"=>"255", "target_branch"=>"develop"}, "namespace_id"=>"obfuscated", "project_id"=>"obfuscated"}
Completed 500 Internal Server Error in 93ms (ActiveRecord: 12.0ms)

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column "latest_merge_request_diff_id" does not exist
LINE 1: ..."."deleted_at" IS NULL AND (id = 914 AND COALESCE(latest_mer...
                                                             ^
: UPDATE "merge_requests" SET "latest_merge_request_diff_id" = 1841 WHERE "merge_requests"."deleted_at" IS NULL AND (id = 914 AND COALESCE(latest_merge_request_diff_id, 0) < 1841)):
  app/models/merge_request_diff.rb:53:in `save_git_content'
  app/models/merge_request.rb:432:in `block in create_merge_request_diff'
  lib/gitlab/gitaly_client.rb:218:in `allow_n_plus_1_calls'
  app/models/merge_request.rb:431:in `create_merge_request_diff'
  app/models/merge_request.rb:424:in `ensure_merge_request_diff'
  app/services/issuable_base_service.rb:121:in `block in create_issuable'
  app/services/issuable_base_service.rb:120:in `create_issuable'
  app/services/issuable_base_service.rb:140:in `create'
  app/services/merge_requests/create_service.rb:18:in `block in execute'
  lib/gitlab/gitaly_client.rb:218:in `allow_n_plus_1_calls'
  app/services/merge_requests/create_service.rb:17:in `execute'
  app/controllers/projects/merge_requests/creations_controller.rb:17:in `create'
  lib/gitlab/i18n.rb:47:in `with_locale'
  lib/gitlab/i18n.rb:53:in `with_user_locale'
  app/controllers/application_controller.rb:336: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'


Started PATCH "/api/v4/jobs/119401/trace" for 192.168.1.obfuscated at 2017-11-23 09:16:18 +0100

Output of checks

This bug DOES NOT happen on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

System information System: Ubuntu 16.04 Current User: git Using RVM: no Ruby Version: 2.3.5p376 Gem Version: 2.6.13 Bundler Version:1.13.7 Rake Version: 12.1.0 Redis Version: 3.2.5 Git Version: 2.13.6 Sidekiq Version:5.0.4 Go Version: unknown

GitLab information Version: 10.2.1 Revision: eb2643f Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: http://192.168.1.obfuscated HTTP Clone URL: http://192.168.1.obfuscated/some-group/some-project.git SSH Clone URL: git@192.168.1.obfuscated:some-group/some-project.git Using LDAP: no Using Omniauth: no

GitLab Shell Version: 5.9.4 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.9.4 ? ... OK (5.9.4) 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: ... 3/9 ... ok 3/10 ... ok 3/11 ... ok 2/12 ... ok 2/13 ... ok 2/14 ... ok 2/15 ... ok 2/16 ... ok 2/17 ... ok 2/18 ... ok 2/19 ... ok 2/20 ... ok 2/21 ... ok 2/22 ... ok 2/23 ... ok 3/25 ... ok 2/26 ... ok 12/27 ... ok 3/28 ... ok 3/30 ... ok 3/32 ... ok 3/33 ... ok 3/34 ... ok 3/35 ... ok 3/36 ... ok 3/37 ... ok 3/49 ... ok 3/53 ... ok 3/54 ... ok 12/55 ... ok 12/56 ... ok 12/57 ... ok 12/59 ... ok 12/60 ... ok 3/61 ... ok 12/62 ... ok 12/63 ... ok 3/64 ... ok 12/84 ... ok 2/88 ... ok 5/89 ... ok 12/90 ... ok 12/91 ... ok 10/96 ... ok 3/99 ... ok 2/100 ... ok 3/101 ... ok 10/102 ... ok 3/104 ... ok 3/105 ... ok 3/108 ... ok 3/109 ... ok 3/113 ... ok 2/115 ... ok 2/117 ... ok 12/119 ... ok 2/121 ... ok 2/122 ... ok 2/128 ... ok 2/129 ... ok 3/132 ... ok 3/133 ... ok 12/134 ... ok 2/135 ... ok 2/136 ... ok 3/137 ... ok 3/138 ... ok 3/139 ... ok 3/140 ... ok 3/142 ... ok 3/144 ... ok 2/145 ... ok 3/146 ... ok 12/147 ... ok 3/148 ... ok 10/149 ... ok 3/150 ... ok 2/151 ... ok 3/152 ... ok 12/154 ... ok 3/155 ... ok 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

Checking Reply by email ...

IMAP server credentials are correct? ... no Try fixing it: An error occurred: OpenSSL::SSL::SSLError: hostname "obfuscated.com" does not match the server certificate Check that the information in config/gitlab.yml is correct For more information see: doc/administration/reply_by_email.md Please fix the error above and rerun the checks. Init.d configured correctly? ... skipped MailRoom running? ... skipped

Checking Reply by email ... Finished

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: ... 3/9 ... yes 3/10 ... yes 3/11 ... yes 2/12 ... yes 2/13 ... yes 2/14 ... yes 2/15 ... yes 2/16 ... yes 2/17 ... yes 2/18 ... yes 2/19 ... yes 2/20 ... yes 2/21 ... yes 2/22 ... yes 2/23 ... yes 3/25 ... yes 2/26 ... yes 12/27 ... yes 3/28 ... yes 3/30 ... yes 3/32 ... yes 3/33 ... yes 3/34 ... yes 3/35 ... yes 3/36 ... yes 3/37 ... yes 3/49 ... yes 3/53 ... yes 3/54 ... yes 12/55 ... yes 12/56 ... yes 12/57 ... yes 12/59 ... yes 12/60 ... yes 3/61 ... yes 12/62 ... yes 12/63 ... yes 3/64 ... yes 12/84 ... yes 2/88 ... yes 5/89 ... yes 12/90 ... yes 12/91 ... yes 10/96 ... yes 3/99 ... yes 2/100 ... yes 3/101 ... yes 10/102 ... yes 3/104 ... yes 3/105 ... yes 3/108 ... yes 3/109 ... yes 3/113 ... yes 2/115 ... yes 2/117 ... yes 12/119 ... yes 2/121 ... yes 2/122 ... yes 2/128 ... yes 2/129 ... yes 3/132 ... yes 3/133 ... yes 12/134 ... yes 2/135 ... yes 2/136 ... yes 3/137 ... yes 3/138 ... yes 3/139 ... yes 3/140 ... yes 3/142 ... yes 3/144 ... yes 2/145 ... yes 3/146 ... yes 12/147 ... yes 3/148 ... yes 10/149 ... yes 3/150 ... yes 2/151 ... yes 3/152 ... yes 12/154 ... yes 3/155 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.3.5) Git version >= 2.7.3 ? ... yes (2.13.6) Git user has default SSH configuration? ... yes Active users: ... 10

Checking GitLab ... Finished

Possible fixes

Seems like an SQL issue, failed update?

Edited by Alexandre