Browse Source

Retry in case of stale issue during Issue.update_versions (#38820).

Patch by Jens Krämer.


git-svn-id: https://svn.redmine.org/redmine/trunk@22279 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/5.1.0
Go MAEDA 10 months ago
parent
commit
86c5d7814f
2 changed files with 47 additions and 3 deletions
  1. 12
    3
      app/models/issue.rb
  2. 35
    0
      test/unit/issue_test.rb

+ 12
- 3
app/models/issue.rb View File

@@ -1891,9 +1891,18 @@ class Issue < ActiveRecord::Base
next if issue.project.nil? || issue.fixed_version.nil?

unless issue.project.shared_versions.include?(issue.fixed_version)
issue.init_journal(User.current)
issue.fixed_version = nil
issue.save
retried = false
begin
issue.init_journal(User.current)
issue.fixed_version = nil
issue.save
rescue ActiveRecord::StaleObjectError
raise if retried

retried = true
issue.reload
retry
end
end
end
end

+ 35
- 0
test/unit/issue_test.rb View File

@@ -3489,6 +3489,41 @@ class IssueTest < ActiveSupport::TestCase
end
end

def test_change_of_project_parent_should_update_shared_versions_with_derived_priorities
with_settings('parent_issue_priority' => 'derived') do
parent = Project.find 1
child = Project.find 3
assert_equal parent, child.parent
assert version = parent.versions.create(name: 'test', sharing: 'descendants')
assert version.persisted?
assert child.shared_versions.include?(version)

# create a situation where the child issue id is lower than the parent issue id.
# When the parent project is removed, the version inherited from there will be removed from
# both issues. At least on MySQL the record with the lower Id will be processed first.
#
# If this update on the child triggers an update on the parent record (here, due to the derived
# priority), the already loaded parent issue is considered stale when it's version is updated.
assert child_issue = child.issues.first
parent_issue = Issue.create! project: child, subject: 'test', tracker: child_issue.tracker, author: child_issue.author, status: child_issue.status, fixed_version: version
assert child_issue.update fixed_version: version, priority_id: 6, parent: parent_issue
parent_issue.update_column :priority_id, 4 # force a priority update when the version is nullified

assert child.update parent: nil

child.reload
assert !child.shared_versions.include?(version)

child_issue.reload
assert_nil child_issue.fixed_version
assert_equal 6, child_issue.priority_id

parent_issue.reload
assert_nil parent_issue.fixed_version
assert_equal 6, parent_issue.priority_id
end
end

def test_create_should_not_add_anonymous_as_watcher
Role.anonymous.add_permission!(:add_issue_watchers)


Loading…
Cancel
Save