Editing MR shows 500 error if the source project was deleted
Summary
When trying to edit an MR of which the source project was already deleted, GitLab returns 500 error.
Steps to reproduce
- Create a project.
- Fork it to a different namespace or group.
- Create a branch, push something and submit an MR from the fork.
- Go back to original project and merge MR (with delete source branch option enabled).
- Delete the fork (source of MR) project.
- Now, try to edit the MR from original project. It will give 500 error.
Example Project
Could not reproduce this on GitLab.com. Though, I have created this project for testing. Not sure if editing MR is working because the source project is still not hard deleted (which is now pending for deletion).
What is the current bug behavior?
GitLab returns 500 error while attempting to edit an MR of which the source project was deleted.
What is the expected correct behavior?
User should be able to edit the MR. If this should not be allowed, at least a helpful message must be shown.
Relevant logs and/or screenshots
Log:
==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/sw/aksjdhkjas/-/merge_requests/2/edit" for 10.20.0.1 at 2020-05-18 05:43:16 +0000
Processing by Projects::MergeRequestsController#edit as HTML
Parameters: {"namespace_id"=>"sw", "project_id"=>"aksjdhkjas", "id"=>"2"}
Completed 500 Internal Server Error in 156ms (ActiveRecord: 8.8ms | Elasticsearch: 0.0ms | Allocations: 179691)
ActionView::Template::Error (undefined method `empty_repo?' for nil:NilClass):
8: %label
9: = _('Merge options')
10: .col-sm-10
11: - if issuable.can_remove_source_branch?(current_user)
12: .form-check.append-bottom-default
13: = hidden_field_tag 'merge_request[force_remove_source_branch]', '0', id: nil
14: = check_box_tag 'merge_request[force_remove_source_branch]', '1', issuable.force_remove_source_branch?, class: 'form-check-input'
app/models/protected_branch.rb:24:in `protected?'
app/models/merge_request.rb:936:in `can_remove_source_branch?'
app/views/shared/issuable/form/_merge_params.html.haml:11
app/views/shared/issuable/_form.html.haml:38
app/views/projects/merge_requests/_form.html.haml:3
app/views/projects/merge_requests/_form.html.haml:1
app/views/projects/merge_requests/edit.html.haml:5
app/controllers/application_controller.rb:125:in `render'
ee/lib/gitlab/ip_address_state.rb:10:in `with'
ee/app/controllers/ee/application_controller.rb:43:in `set_current_ip_address'
app/controllers/application_controller.rb:479:in `set_current_admin'
lib/gitlab/session.rb:11:in `with_session'
app/controllers/application_controller.rb:470:in `set_session_storage'
lib/gitlab/i18n.rb:55:in `with_locale'
lib/gitlab/i18n.rb:61:in `with_user_locale'
app/controllers/application_controller.rb:464:in `set_locale'
lib/gitlab/error_tracking.rb:48:in `with_context'
app/controllers/application_controller.rb:559:in `sentry_context'
lib/gitlab/application_context.rb:52:in `block in use'
lib/gitlab/application_context.rb:52:in `use'
lib/gitlab/application_context.rb:20:in `with_context'
app/controllers/application_controller.rb:455:in `set_current_context'
lib/gitlab/middleware/rails_queue_duration.rb:29:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:62:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
ee/lib/gitlab/jira/middleware.rb:19:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/multipart.rb:124:in `call'
lib/gitlab/middleware/read_only/controller.rb:53:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/same_site_cookies.rb:27:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/middleware/request_context.rb:23:in `call'
config/initializers/fix_local_cache_middleware.rb:9:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:60:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
Screenshot:
Results of GitLab environment info
root@12103-ee:/home/vagrant# gitlab-rake gitlab:env:info
System information
System: Ubuntu 16.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.6.5p114
Gem Version: 2.7.10
Bundler Version:1.17.3
Rake Version: 12.3.3
Redis Version: 5.0.7
Git Version: 2.26.2
Sidekiq Version:5.2.7
Go Version: unknown
GitLab information
Version: 12.10.3-ee
Revision: 7c0ab260960
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 11.7
URL: http://12103-ee
HTTP Clone URL: http://12103-ee/some-group/some-project.git
SSH Clone URL: git@12103-ee:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 12.2.0
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
root@12103-ee:/home/vagrant# sudo gitlab-rake gitlab:check SANITIZE=true
Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 12.2.0 ? ... OK (12.2.0)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
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? ... skipped (no tmp uploads folder yet)
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/1 ... yes
Redis version >= 4.0.0? ... yes
Ruby version >= 2.5.3 ? ... yes (2.6.5)
Git version >= 2.22.0 ? ... yes (2.26.2)
Git user has default SSH configuration? ... yes
Active users: ... 1
Is authorized keys file accessible? ... yes
Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Note: I think this is a related issue : #28631 (closed)