プロジェクト

全般

プロフィール

Vote #79878

未完了

Issue#clear_disabled_fields can still lead to a nil done_ratio in some cases

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Issues_2
対象バージョン:
-
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
2
version_id:
0
issue_org_id:
30950
author_id:
123866
assigned_to_id:
0
comments:
1
status_id:
1
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
146
ステータス-->[New]

説明

This seems to occur on all Redmine versions since 3.0.0 (#5991), but it is a rare bug so it has a relatively low impact.

There is a database constraint + model constraint, where Issue#done_ratio cannot be nil.
Yet, in a specific case, Issue#clear_disabled_fields will not properly read the actual done_ratio value, leaving a nil value which leads to a 500 error.

h3. How to reproduce:

  • Configure redmine with use_status_for_done_ratio to true
  • Create an IssueStatus "test_status", give it a default done ratio (e.g. 0%)
  • Create a tracker "test_tracker", set its default status to "test_status", uncheck done_ratio field
  • Attempt to create an issue with tracker "test_tracker", with status "test_status" -> 500 Error

h3. Why it happens

Because of "Issue#done_ratio":https://github.com/redmine/redmine/blob/0c78056a69cc3bee7fb1cd3261046995db55bfdf/app/models/issue.rb#L696


def done_ratio
  if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
    status.default_done_ratio #ratio is returned from here
  else
    read_attribute(:done_ratio)
  end
end

and

"Issue#clear_disabled_fields":https://github.com/redmine/redmine/blob/0c78056a69cc3bee7fb1cd3261046995db55bfdf/app/models/issue.rb#L1855 :


def clear_disabled_fields
  if tracker
    tracker.disabled_core_fields.each do |attribute|
      send "#{attribute}=", nil #done_ratio is set to nil here
    end
    self.done_ratio ||= 0 #But here, the underlying nil done ratio is not detected, because it is not read from read_attribute in this special case.
  end
end

h3. How we can fix it

With the following fix, the error won't happen:


def clear_disabled_fields
  if tracker
    tracker.disabled_core_fields.each do |attribute|
      send "#{attribute}=", nil #done_ratio is set to nil here
    end
    unless read_attribute(:done_ratio)
      self.done_ratio = 0
    end
  end
end

journals

Stephane Evr wrote:
> h3. How to reproduce:
>
> - Configure redmine with use_status_for_done_ratio to true
> - Create an IssueStatus "test_status", give it a default done ratio (e.g. 0%)
> - Create a tracker "test_tracker", set its default status to "test_status", *uncheck* done_ratio field
> - Attempt to create an issue with tracker "test_tracker", with status "test_status"
> -> 500 Error

I followed the steps above, but I was not able to reproduce the problem.
--------------------------------------------------------------------------------

Admin Redmine さんが約4年前に更新

  • カテゴリIssues_2 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0