Defect #13118

a_issue.project.issue_custom_fields don't work always correct

Added by Thomas Kohler over 9 years ago. Updated over 9 years ago.

Status:ReopenedStart date:
Priority:NormalDue date:
Assignee:-% Done:


Category:Custom fields
Target version:-
Resolution:Invalid Affected version:


This means "a_issue.project.issue_custom_fields" and "Project.find_by_id(" 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.issue_custom_fields).empty?

The same for trackers:
(Tracker.find_by_id( - a_issue.tracker.custom_fields).empty?

tc_redmine_defect_13118.rb Magnifier - to reproduce the bad case and the solution (4.18 KB) Thomas Kohler, 2013-02-11 22:17

test_helper_for_redmine_defects.rb Magnifier - a helper class for the tests (4.87 KB) Thomas Kohler, 2013-02-11 22:19


#1 Updated by Jean-Philippe Lang over 9 years ago

  • Resolution set to Cant reproduce

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

#2 Updated by Thomas Kohler over 9 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.issue_custom_fields).empty?
puts "Found this bug for project:!"
if !(Tracker.find_by_id( - self.tracker.custom_fields).empty?
puts "Found this bug for tracker:!"
#workaround for this bug:
this_project = Project.find_by_id(
this_tracker = Tracker.find_by_id(
retval= (this_project && this_tracker) ? (this_project.all_issue_custom_fields & this_tracker.custom_fields.all) : []
return retval

Now I have detected the problem also once for trackers.

#3 Updated by Jean-Philippe Lang over 9 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(" give sometimes different results.

a_issue.project and Project.find_by_id( are not the same objects in memory. You can try:

a_issue.project.object_id == Project.find_by_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.

#4 Updated by Thomas Kohler over 9 years ago

Yes, you are right! I have given that the 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 What do you think about?

def available_custom_fields
if !(Project.find_by_id( - self.project.issue_custom_fields).empty?
if !(Tracker.find_by_id( - self.tracker.custom_fields).empty?
retval= (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : []
return retval

#5 Updated by Thomas Kohler over 9 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".

Also available in: Atom PDF