Commit febd428e authored by Felipe Artur's avatar Felipe Artur Committed by Heinrich Lee Yu

Prevent calling state machines initializer for issuables

Remove the overridden Issuable.initialize patch and prevent
calling overriden initializer on state machines for issues
and merge requests
parent a4c09848
......@@ -148,26 +148,6 @@ module Issuable
strip_attributes :title
# The state_machine gem will reset the value of state_id unless it
# is a raw attribute passed in here:
# https://gitlab.com/gitlab-org/gitlab/issues/35746#note_241148787
#
# This assumes another initialize isn't defined. Otherwise this
# method may need to be prepended.
def initialize(attributes = nil)
if attributes.is_a?(Hash)
attr = attributes.symbolize_keys
if attr.key?(:state) && !attr.key?(:state_id)
value = attr.delete(:state)
state_id = self.class.available_states[value]
attributes[:state_id] = state_id if state_id
end
end
super(attributes)
end
# We want to use optimistic lock for cases when only title or description are involved
# http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
def locking_enabled?
......
......@@ -77,7 +77,7 @@ class Issue < ApplicationRecord
attr_spammable :title, spam_title: true
attr_spammable :description, spam_description: true
state_machine :state_id, initial: :opened do
state_machine :state_id, initial: :opened, initialize: false do
event :close do
transition [:opened] => :closed
end
......
......@@ -103,7 +103,7 @@ class MergeRequest < ApplicationRecord
super + [:merged, :locked]
end
state_machine :state_id, initial: :opened do
state_machine :state_id, initial: :opened, initialize: false do
event :close do
transition [:opened] => :closed
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