First MR page load broken after removing source repository.

In an attempt to reproduce #38334 (closed) I created a MR first and then removed the source repository. After removing the source repo I refreshed the MR page and got a HTTP 500. Following error could be found in the logs :

ActionView::Template::Error (undefined method `merge_commit?' for nil:NilClass):
    18:       = render "projects/merge_requests/how_to_merge"
    19:
    20:     = javascript_tag nonce: true do
    21:       :plain
    22:         window.gl = window.gl || {};
    23:         window.gl.mrWidgetData = #{serialize_issuable(@merge_request, serializer: 'widget', issues_links: true)}
    24:

app/models/commit_collection.rb:33:in `reject'
app/models/commit_collection.rb:33:in `block in without_merge_commits'
lib/gitlab/utils/strong_memoize.rb:30:in `strong_memoize'
app/models/commit_collection.rb:30:in `without_merge_commits'
app/models/merge_request.rb:1008:in `block in default_squash_commit_message'
lib/gitlab/utils/strong_memoize.rb:30:in `strong_memoize'
app/models/merge_request.rb:1007:in `default_squash_commit_message'
lib/gitlab/metrics/instrumentation.rb:161:in `block in default_squash_commit_message'
lib/gitlab/metrics/method_call.rb:36:in `measure'
lib/gitlab/metrics/instrumentation.rb:161:in `default_squash_commit_message'
app/serializers/merge_request_widget_entity.rb:69:in `as_json'
app/serializers/base_serializer.rb:16:in `represent'
app/serializers/merge_request_serializer.rb:23:in `represent'
app/helpers/issuables_helper.rb:87:in `serialize_issuable'
app/views/projects/merge_requests/show.html.haml:21:in `block in _app_views_projects_merge_requests_show_html_haml___3854330222773701704_46990474497200'
app/views/projects/merge_requests/show.html.haml:20:in `_app_views_projects_merge_requests_show_html_haml___3854330222773701704_46990474497200'
app/controllers/application_controller.rb:118:in `render'
app/controllers/projects/merge_requests_controller.rb:55:in `block (2 levels) in show'
app/controllers/projects/merge_requests_controller.rb:39:in `show'
app/controllers/application_controller.rb:533:in `block in allow_gitaly_ref_name_caching'
lib/gitlab/gitaly_client.rb:300:in `allow_ref_name_caching'
app/controllers/application_controller.rb:532:in `allow_gitaly_ref_name_caching'
lib/gitlab/session.rb:11:in `with_session'
app/controllers/application_controller.rb:450: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:444:in `set_locale'
lib/gitlab/middleware/rails_queue_duration.rb:27:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:57:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/correlation_id.rb:16:in `block in call'
lib/gitlab/middleware/correlation_id.rb:15:in `call'
lib/gitlab/middleware/multipart.rb:117:in `call'
lib/gitlab/middleware/read_only/controller.rb:42:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:26:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:29:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
Assignee Loading
Time tracking Loading