backlogs / redmine_backlogs

A Redmine plugin for agile teams
https://backlogs.github.io/www/
GNU General Public License v2.0
773 stars 460 forks source link

Internal error on copying a Story with sub tasks that are assigned to closed version/sprint #1032

Open stefan-langenmaier opened 10 years ago

stefan-langenmaier commented 10 years ago

Environment: Redmine version 2.3.2.stable Ruby version 2.0.0-p353 (2013-11-22) [x86_64-linux] Rails version 3.2.13 Environment production Database adapter Mysql2 Redmine plugins: redmine_backlogs v1.0.4

I have a problem when copying a story with its sub tasks. It only appears when the backlogs plugin is installed and only for stories with subtasks assigned to sprints that are closed.

I receive the following error in the log file:

Started POST "/projects/XXX/issues" for 127.0.0.1 at 2014-02-18 16:48:06 -0500
Processing by IssuesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"XXX", "copy_from"=>"27700", "issue"=>{"is_private"=>"0", "project_id"=>"374", "tracker_id"=>"5", "subject"=>XXX", "description"=>"XXX", "status_id"=>"6", "priority_id"=>"5", "assigned_to_id"=>"", "category_id"=>"474", "fixed_version_id"=>"2315", "parent_issue_id"=>"", "start_date"=>"2013-07-30", "due_date"=>"", "estimated_hours"=>"82.0", "done_ratio"=>"100", "story_points"=>"21.0", "release_id"=>"", "release_relationship"=>"auto"}, "link_to_original"=>"27700", "copy_tasks"=>"all:27700", "commit"=>"Create", "project_id"=>"XXX"}
  Current user: admin (id=1)
  Rendered mailer/_issue.text.erb (1.3ms)
  Rendered mailer/issue_add.text.erb within layouts/mailer (58.0ms)
Completed 422 Unprocessable Entity in 2251ms

ActiveRecord::RecordInvalid (Validation failed: Target version is not included in the list):
  lib/redmine/hook.rb:61:in `block (2 levels) in call_hook'
  lib/redmine/hook.rb:61:in `each'
  lib/redmine/hook.rb:61:in `block in call_hook'
  lib/redmine/hook.rb:58:in `tap'
  lib/redmine/hook.rb:58:in `call_hook'
  lib/redmine/hook.rb:153:in `call_hook'
  app/controllers/issues_controller.rb:142:in `create'

When I apply the following patch, my issues are gone. I can select a Version/Sprint in the dialog and it gets assigned to the Story and the sub tasks. If I leave it empty the Story and the sub tasks are not assigned to a Version/Sprint. Just as intended.

What I want to know is, what is the root cause for this and how can it be properly fixed?

diff --git a/lib/backlogs_hooks.rb b/lib/backlogs_hooks.rb
index 99fd187..4c7f483 100644
--- a/lib/backlogs_hooks.rb
+++ b/lib/backlogs_hooks.rb
@@ -332,6 +332,7 @@ module BacklogsPlugin
                 nt.copy_from(t)
                 nt.parent_issue_id = issue.id
                 nt.position = nil # will assign a new position
+                nt.fixed_version = nil
                 nt.save!
               }
             end