Error 500 when searching for a comment on a diff with a garbage-collected commit
ZenDesk: https://gitlab.zendesk.com/agent/tickets/29925
Steps to reproduce:
- Create a MR with a commit.
- Comment on the MR: "cross"
- Create a new commit, squash the old one.
- Run
git gc --prune
on the bare repo to remove the commit - Run Search in the project for "cross"
Error 500 results:
Started POST "/ci/api/v1/builds/register.json" for 127.0.0.1 at 2016-07-13 11:30:32 -0400
Started GET "/search?project_id=14&scope=notes&search=cross" for 127.0.0.1 at 2016-07-13 11:30:32 -0400
Processing by SearchController#show as HTML
Parameters: {"project_id"=>"14", "scope"=>"notes", "search"=>"cross"}
Started GET "/e/bnv/notes?target_id=4326&target_type=issue&last_fetched_at=1468423712" for 127.0.0.1 at 2016-07-13 11:30:32 -0400
Processing by Projects::NotesController#index as JSON
Parameters: {"target_id"=>"4326", "target_type"=>"issue", "last_fetched_at"=>"1468423712", "namespace_id"=>"e", "project_id"=>"bnv"}
Started POST "/ci/api/v1/builds/register.json" for 127.0.0.1 at 2016-07-13 11:30:32 -0400
Completed 200 OK in 63ms (Views: 0.3ms | ActiveRecord: 4.8ms)
Completed 500 Internal Server Error in 313ms (ActiveRecord: 43.2ms)
ActionView::Template::Error (undefined method `id' for nil:NilClass):
1: - project = note.project
2: - note_url = Gitlab::UrlBuilder.build(note)
3: - noteable_identifier = note.noteable.try(:iid) || note.noteable.id
4: .search-result-row
5: %h5.note-search-caption.str-truncated
6: %i.fa.fa-comment
app/views/search/results/_note.html.haml:3:in `_app_views_search_results__note_html_haml___1128430192865170717_212933820'
app/views/search/_results.html.haml:18:in `_app_views_search__results_html_haml__2164574602782129379_189213060'
app/views/search/show.html.haml:7:in `_app_views_search_show_html_haml___149068321457338556_206460960'
lib/gitlab/middleware/go.rb:16:in `call'
lib/gitlab/middleware/readonly_geo.rb:29:in `call'