Project

General

Profile

Actions

Defect #13118

open

a_issue.project.issue_custom_fields don't work always correct

Added by Thomas Kohler about 11 years ago. Updated about 11 years ago.

Status:
Reopened
Priority:
Normal
Assignee:
-
Category:
Custom fields
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid
Affected version:

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

tc_redmine_defect_13118.rb (4.18 KB) tc_redmine_defect_13118.rb to reproduce the bad case and the solution Thomas Kohler, 2013-02-11 22:17
test_helper_for_redmine_defects.rb (4.87 KB) test_helper_for_redmine_defects.rb a helper class for the tests Thomas Kohler, 2013-02-11 22:19
Actions #1

Updated by Jean-Philippe Lang about 11 years ago

  • Resolution set to Cant reproduce

Works for me on my development environment. Can you provide a failing test?

Actions #2

Updated by Thomas Kohler about 11 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.

Actions #3

Updated by Jean-Philippe Lang about 11 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.

Actions #4

Updated by Thomas Kohler about 11 years ago

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

Updated by Thomas Kohler about 11 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".

Actions

Also available in: Atom PDF