Defect #13118
opena_issue.project.issue_custom_fields don't work always correct
0%
Description
This means "a_issue.project.issue_custom_fields" and "Project.find_by_id(a_issue.project.id).issue_custom_fields" give sometimes different results. This also affect the result of the method "available_custom_fields" in issue.rb. This is only sometimes the case - don't no why.
Especially in that case "a_issue.project.issue_custom_fields.count" give also a wrong value (count like expected, but some expected entries are nil)
A simple detection is possible with:
(Project.find_by_id(a_issue.project.id).issue_custom_fields - a_issue.project.issue_custom_fields).empty?
The same for trackers:
(Tracker.find_by_id(a_issue.tracker.id).custom_fields - a_issue.tracker.custom_fields).empty?
Files
Updated by Jean-Philippe Lang almost 12 years ago
- Resolution set to Cant reproduce
Works for me on my development environment. Can you provide a failing test?
Updated by Thomas Kohler almost 12 years ago
I will try it. But for now I'm using this method for workaround and detection:
'# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
def available_custom_fields
if !(Project.find_by_id(self.project.id).issue_custom_fields - self.project.issue_custom_fields).empty?
debugger
puts "Found this bug for project: http://www.redmine.org/issues/13118!"
end
if !(Tracker.find_by_id(self.tracker.id).custom_fields - self.tracker.custom_fields).empty?
debugger
puts "Found this bug for tracker: http://www.redmine.org/issues/13118!"
end
#workaround for this bug:
this_project = Project.find_by_id(self.project.id)
this_tracker = Tracker.find_by_id(self.tracker.id)
retval= (this_project && this_tracker) ? (this_project.all_issue_custom_fields & this_tracker.custom_fields.all) : []
return retval
end
Now I have detected the problem also once for trackers.
Updated by Jean-Philippe Lang almost 12 years ago
- Status changed from New to Closed
- Resolution changed from Cant reproduce to Invalid
Thomas Kohler wrote:
This means "a_issue.project.issue_custom_fields" and "Project.find_by_id(a_issue.project.id).issue_custom_fields" give sometimes different results.
a_issue.project
and Project.find_by_id(a_issue.project.id)
are not the same objects in memory. You can try:
a_issue.project.object_id == Project.find_by_id(a_issue.project.id).object_id
So if you update an association (eg. add a tracker or a custom field to a project), you may need to #reload
your issue in order to see the new association.
I'm closing it, please reopen if you have a valid failing test.
Updated by Thomas Kohler almost 12 years ago
- File tc_redmine_defect_13118.rb tc_redmine_defect_13118.rb added
- File test_helper_for_redmine_defects.rb test_helper_for_redmine_defects.rb added
Yes, you are right! I have given that the a_issue.save do that already, but unfortunately not.
I have finished a failing test now and also a test with your solution. In my opinion a #reload in the method would be a good idea. Or inside the Issue.save? What do you think about?
def available_custom_fields
if !(Project.find_by_id(self.project.id).issue_custom_fields - self.project.issue_custom_fields).empty?
self.reload
end
if !(Tracker.find_by_id(self.tracker.id).custom_fields - self.tracker.custom_fields).empty?
self.reload
end
retval= (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : []
return retval
end
Updated by Thomas Kohler almost 12 years ago
- Status changed from Closed to Reopened
Please check my failing test and post your opinion about "reload in the #available_custom_fields or on/after #save of the issue".