Vote #79878
未完了Issue#clear_disabled_fields can still lead to a nil done_ratio in some cases
0%
説明
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.
--------------------------------------------------------------------------------