You need to sign in or sign up before continuing.
Upgrading to 11.9.0 results in a Error 500 on every page when active broadcast message present
Steps to reproduce:
- Install GitLab 11.9.0 RC7.
- Create a new, active broadcast message.
- Visit any page and see Error 500:
Completed 500 Internal Server Error in 2898ms (ActiveRecord: 50.2ms | Elasticsearch: 0.0ms)
ActionView::Template::Error (missing attribute: message_html):
1: - BroadcastMe
2: = broadcast_message(message)
app/models/concerns/cache_markdown_field.rb:114:in `cached_html_for'
app/models/concerns/cache_markdown_field.rb:93:in `cached_html_up_to_date?'
lib/banzai/renderer.rb:42:in `render_field'
lib/gitlab/metrics/instrumentation.rb:161:in `block in render_field'
lib/gitlab/metrics/method_call.rb:36:in `measure'
lib/gitlab/metrics/instrumentation.rb:161:in `render_field'
lib/banzai.rb:16:in `render_field'
app/helpers/broadcast_messages_helper.rb:37:in `render_broadcast_message'
app/helpers/broadcast_messages_helper.rb:8:in `block in broadcast_message'
app/helpers/broadcast_messages_helper.rb:7:in `broadcast_message'
app/views/layouts/_broadcast.html.haml:2:in `block in _app_views_layouts__broadcast_html_haml__3905053517267204482_70298889008040'
app/views/layouts/_broadcast.html.haml:1:in `each'
app/views/layouts/_broadcast.html.haml:1:in `_app_views_layouts__broadcast_html_haml__3905053517267204482_70298889008040'
app/views/layouts/_page.html.haml:9:in `_app_views_layouts__page_html_haml___2078437330754864283_70298873657680'
app/views/layouts/application.html.haml:10:in `_app_views_layouts_application_html_haml___937080076175994636_70298841706420'
app/views/layouts/dashboard.html.haml:6:in `_app_views_layouts_dashboard_html_haml___4233209330808554035_70298787497580'
app/controllers/application_controller.rb:116:in `render'
app/controllers/dashboard/projects_controller.rb:20:in `block (3 levels) in index'
lib/gitlab/gitaly_client.rb:283:in `allow_n_plus_1_calls'
app/controllers/dashboard/projects_controller.rb:19:in `block (2 levels) in index'
app/controllers/dashboard/projects_controller.rb:15:in `index'
app/controllers/root_controller.rb:20:in `block in index'
lib/gitlab/gitaly_client.rb:283:in `allow_n_plus_1_calls'
app/controllers/root_controller.rb:19:in `index'
lib/gitlab/i18n.rb:55:in `with_locale'
@athar and I did some debugging and found that this a ~P1 regression caused by e96f2f24.
The key lines are in the last two lines of JsonCache#parse_entry
:
def parse_entry(raw, klass)
return unless valid_entry?(raw, klass)
return klass.new(raw) unless klass.ancestors.include?(ActiveRecord::Base)
# When the cached value is a persisted instance of ActiveRecord::Base in
# some cases a relation can return an empty collection becauses scope.none!
# is being applied on ActiveRecord::Associations::CollectionAssociation#scope
# when the new_record? method incorrectly returns false.
#
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/9903#note_145329964
attributes = klass.attributes_builder.build_from_database(raw, {})
klass.allocate.init_with("attributes" => attributes, "new_record" => new_record?(raw, klass))
end
Since BroadcastMessage
is an ActiveRecord::Base
, the last two lines are executed. It seems that since raw
does NOT include the dynamically generated message_html
field, for some reason the returned model does not have message_html
as an attribute:
irb(main):153:0> BroadcastMessage.current
=> [#<BroadcastMessage id: 1, message: "Here's a new broadcast message", starts_at: "2019-03-20 03:13:00", ends_at: "2024-03-20 03:13:00", created_at: "2019-03-20 03:13:58", updated_at: "2019-03-20 03:13:58", color: "#e75e40", font: "#ffffff">, #<BroadcastMessage id: 2, message: "Can I create more than 1?", starts_at: "2019-03-20 03:13:00", ends_at: "2022-03-20 03:13:00", created_at: "2019-03-20 03:14:11", updated_at: "2019-03-20 03:14:11", color: "#e75e40", font: "#ffffff">]
irb(main):159:0> BroadcastMessage.current.first.message_html
Traceback (most recent call last):
14: from bin/rails:4:in `<main>'
13: from bin/rails:4:in `require'
12: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/railties-5.0.7.1/lib/rails/commands.rb:18:in `<top (required)>'
11: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/railties-5.0.7.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
10: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/railties-5.0.7.1/lib/rails/commands/commands_tasks.rb:78:in `console'
9: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/railties-5.0.7.1/lib/rails/commands/console_helper.rb:9:in `start'
8: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/railties-5.0.7.1/lib/rails/commands/console.rb:65:in `start'
7: from (irb):159
6: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/attribute_methods/read.rb:36:in `__temp__d6563737167656f58647d6c6'
5: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/attribute_methods/read.rb:66:in `_read_attribute'
4: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/attribute_set.rb:44:in `fetch_value'
3: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/attribute.rb:196:in `value'
2: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/attribute_set.rb:44:in `block in fetch_value'
1: from /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/attribute_methods/read.rb:66:in `block in _read_attribute'
ActiveModel::MissingAttributeError (missing attribute: message_html)
/cc: @dbalexandre, @ashmckenzie, @yorickpeterse, @jarv
Edited by Stan Hu