Commit 6d6b178c authored by Arturo Herrero's avatar Arturo Herrero

Use each_batch instead of in_batches

If we use a query that doesn't return all the columns, we can get this
error, as we are having using Service.each_batch.

    Failure/Error: self.properties = {} if properties.nil?

    ActiveModel::MissingAttributeError:
      missing attribute: properties
    # ./app/models/service.rb:281:in `initialize_properties'
    # ./app/models/concerns/each_batch.rb:61:in `each_batch'

We have to use has_attribute? to avoid the
ActiveRecord::MissingAttributeError error.
parent 2ee7dccf
......@@ -8,6 +8,7 @@ class Service < ApplicationRecord
include ProjectServicesLoggable
include DataFields
include FromUnion
include EachBatch
SERVICE_NAMES = %w[
alerts asana assembla bamboo bugzilla buildkite campfire confluence custom_issue_tracker discord
......@@ -294,7 +295,7 @@ class Service < ApplicationRecord
end
def initialize_properties
self.properties = {} if properties.nil?
self.properties = {} if has_attribute?(:properties) && properties.nil?
end
def title
......
......@@ -20,7 +20,7 @@ module Admin
# rubocop: disable Cop/InBatches
def update_inherited_integrations
Service.by_type(integration.type).inherit_from_id(integration.id).in_batches(of: BATCH_SIZE) do |services|
Service.by_type(integration.type).inherit_from_id(integration.id).each_batch(of: BATCH_SIZE) do |services|
min_id, max_id = services.pick("MIN(services.id), MAX(services.id)")
PropagateIntegrationInheritWorker.perform_async(integration.id, min_id, max_id)
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