Commit 707bb9dc authored by Rubén Dávila Santos's avatar Rubén Dávila Santos Committed by Ruben Davila

Merge branch 'fix-network-graph-error-500' into 'master'

Fix Error 500 resulting when loading network graph

`discussion_id` may not be present when the SELECT call for notes does not include this attribute. Don't attempt to set the discussion ID unless the model contains the attribute:

```ruby
irb(main):019:0> notes[0]
  Note Load (10.3ms)  SELECT notes.commit_id, count(notes.id) as note_count FROM "notes" WHERE "notes"."project_id" = $1 AND (noteable_type = 'Commit') GROUP BY notes.commit_id  [["project_id", 13083]]
ActiveModel::MissingAttributeError: missing attribute: discussion_id
```

Closes #21119, #21128

See merge request !5922
parent 8df13ef6
......@@ -259,6 +259,8 @@ class Note < ActiveRecord::Base
def ensure_discussion_id
return unless self.persisted?
# Needed in case the SELECT statement doesn't ask for `discussion_id`
return unless self.has_attribute?(:discussion_id)
return if self.discussion_id
set_discussion_id
......
require 'spec_helper'
describe Network::Graph, models: true do
let(:project) { create(:project) }
let!(:note_on_commit) { create(:note_on_commit, project: project) }
it '#initialize' do
graph = described_class.new(project, 'refs/heads/master', project.repository.commit, nil)
expect(graph.notes).to eq( { note_on_commit.commit_id => 1 } )
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment