Project

General

Profile

Patch #38820 » 0001-retry-in-case-of-stale-issue-during-Issue.update_ver.patch

Jens Krämer, 2023-07-06 16:13

View differences:

app/models/issue.rb
1891 1891
        next if issue.project.nil? || issue.fixed_version.nil?
1892 1892

  
1893 1893
        unless issue.project.shared_versions.include?(issue.fixed_version)
1894
          issue.init_journal(User.current)
1895
          issue.fixed_version = nil
1896
          issue.save
1894
          retried = false
1895
          begin
1896
            issue.init_journal(User.current)
1897
            issue.fixed_version = nil
1898
            issue.save
1899
          rescue ActiveRecord::StaleObjectError
1900
            raise if retried
1901
            retried = true
1902
            issue.reload
1903
            retry
1904
          end
1897 1905
        end
1898 1906
      end
1899 1907
    end
test/unit/issue_test.rb
3489 3489
    end
3490 3490
  end
3491 3491

  
3492
  def test_change_of_project_parent_should_update_shared_versions_with_derived_priorities
3493
    with_settings('parent_issue_priority' => 'derived') do
3494
      parent = Project.find 1
3495
      child = Project.find 3
3496
      assert_equal parent, child.parent
3497
      assert version = parent.versions.create(name: 'test', sharing: 'descendants')
3498
      assert version.persisted?
3499
      assert child.shared_versions.include?(version)
3500

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

  
3512
      assert child.update parent: nil
3513

  
3514
      child.reload
3515
      assert !child.shared_versions.include?(version)
3516

  
3517
      child_issue.reload
3518
      assert_nil child_issue.fixed_version
3519
      assert_equal 6, child_issue.priority_id
3520

  
3521
      parent_issue.reload
3522
      assert_nil parent_issue.fixed_version
3523
      assert_equal 6, parent_issue.priority_id
3524
    end
3525
  end
3526

  
3492 3527
  def test_create_should_not_add_anonymous_as_watcher
3493 3528
    Role.anonymous.add_permission!(:add_issue_watchers)
3494 3529

  
    (1-1/1)