Defect #13518

To copy project doesn't copy the issues' custom fields in version 2.2.3

Added by Guillem TanyĆ  Palacios over 9 years ago. Updated over 5 years ago.

Status:Needs feedbackStart date:
Priority:NormalDue date:
Assignee:-% Done:


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


In Redmine version 2.2.3, when you copy a project that the issues have custom fields, this fields aren't copied.

In a previous release of Redmine (2.1.2) this problem is resolved.
The solution could be the same that is explained in the #11315:
This solution consist in:

  • Modify the file app/models/issue.rb to add a call to a function to recalculate the custom fields
    • In tracker_id function:
      def tracker_id=(tid)
           self.tracker = nil
           result = write_attribute(:tracker_id, tid)
      -    @custom_field_values = nil
      +    recalculate_custom_field_values!
    • In project function
      def project=(project, keep_tracker=false)
          project_was = self.project
          write_attribute(:project_id, project ? : nil)
          association_instance_set('project', project)
          if project_was && project && project_was != project
      -      @custom_field_values = nil
      +      recalculate_custom_field_values!  
  • Finally, add the new method in lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
    # Recalculate custom_field_values based on current available_custom_fields.
    # We need to make sure no extraneous custom_field_values are saved,
    # #custom_field_values= will only save values for custom fields available
    # to this object.
    def recalculate_custom_field_values!
      cfv_hash = custom_field_values.inject({}) {|h,cfv| h[] = cfv.value; h}
      self.custom_field_values = cfv_hash


My Environment

Ruby version 1.9.3 (x86_64-linux)
RubyGems version 1.8.25
Rack version 1.4
Rails version 3.2.12
Active Record version 3.2.12
Action Pack version 3.2.12
Active Resource version 3.2.12
Action Mailer version 3.2.12
Active Support version 3.2.12
Environment production
Database adapter mysql2

Related issues

Related to Redmine - Defect #11315: When I copy a project it does not copy the issues custom... Needs feedback
Related to Redmine - Defect #11481: Copying Projects (with Tickets) not working Needs feedback
Copied to Redmine - Defect #13540: To copy project doesn't copy the issues' custom fields in... Closed


#1 Updated by Toshi MARUYAMA over 9 years ago

  • Description updated (diff)

#2 Updated by Toshi MARUYAMA about 9 years ago

  • Related to Defect #11481: Copying Projects (with Tickets) not working added

#3 Updated by Mischa The Evil over 5 years ago

  • Status changed from New to Needs feedback

I just came around this issue again and checked whether this issue still persists on current trunk (at r16339). AFAICS, this is fixed by r15318 for #22342. I did some quick tests and wasn't able to reproduce the issue any longer.
Can this be confirmed by somebody?

Also available in: Atom PDF