1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-31 11:37:14 +00:00

Moves create parent issue journal to after_commit hook to work around stale object errors on concurrency (#39437).

Patch by Jens Krämer.

git-svn-id: https://svn.redmine.org/redmine/trunk@22459 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu 2023-11-18 14:40:25 +00:00
parent aa9b681678
commit a54155d206

View File

@ -119,13 +119,14 @@ class Issue < ActiveRecord::Base
after_save :reschedule_following_issues, :update_nested_set_attributes,
:update_parent_attributes, :delete_selected_attachments, :create_journal
# Should be after_create but would be called before previous after_save callbacks
after_save :after_create_from_copy, :create_parent_issue_journal
after_destroy :update_parent_attributes, :create_parent_issue_journal
after_save :after_create_from_copy
after_destroy :update_parent_attributes
# add_auto_watcher needs to run before sending notifications, thus it needs
# to be added after send_notification (after_ callbacks are run in inverse order)
# https://api.rubyonrails.org/v5.2.3/classes/ActiveSupport/Callbacks/ClassMethods.html#method-i-set_callback
after_create_commit :send_notification
after_create_commit :add_auto_watcher
after_commit :create_parent_issue_journal
# Returns a SQL conditions string used to find all issues visible by the specified user
def self.visible_condition(user, options={})
@ -2027,15 +2028,24 @@ class Issue < ActiveRecord::Base
[nil, parent_id]
end
if old_parent_id.present? && old_parent_issue = Issue.visible.find_by_id(old_parent_id)
old_parent_issue.init_journal(User.current)
old_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', child_id, nil)
old_parent_issue.save
if old_parent_id.present?
Issue.transaction do
if old_parent_issue = Issue.visible.lock.find_by_id(old_parent_id)
old_parent_issue.init_journal(User.current)
old_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', child_id, nil)
old_parent_issue.save
end
end
end
if new_parent_id.present? && new_parent_issue = Issue.visible.find_by_id(new_parent_id)
new_parent_issue.init_journal(User.current)
new_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', nil, child_id)
new_parent_issue.save
if new_parent_id.present?
Issue.transaction do
if new_parent_issue = Issue.visible.lock.find_by_id(new_parent_id)
new_parent_issue.init_journal(User.current)
new_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', nil, child_id)
new_parent_issue.save
end
end
end
end