Project

General

Profile

Actions

Defect #30950

open

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

Added by Stephane Evr about 5 years ago. Updated about 5 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Issues
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

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.

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

Why it happens

Because of Issue#done_ratio

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 :

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

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
Actions #1

Updated by Go MAEDA about 5 years ago

Stephane Evr wrote:

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.

Actions

Also available in: Atom PDF