我无法通过REST API创建新问题

时间:2016-05-31 06:05:41

标签: ruby rest ruby-on-rails-4 redmine nomethoderror

我对redmine感到困扰。

当我使用Rest API(来自Microsoft Excel)创建新问题时,发生了内部错误500。 从production.log看,发生了“NoMethodError”(见下面的消息)

Started POST "/redmine/issues.xml?key=XXXXXXX" for XX.XX.XX.XXX at 2016-05-30 14:44:10 +0900
Processing by IssuesController#create as XML Parameters: {"issue"=>`
{"project_id"=>"mt001", "subject"=>"TEST_AI", "tracker_id"=>"6",
"category_id"=>"136", "assigned_to_id"=>"4", "fixed_version_id"=>"93",
"priority_id"=>"2", "parent_issue_id"=>nil, 
"start_date"=>"2016-05-30", "due_date"=>"2016-06-01", 
"description"=>"Redmine TEST AI", "status_id"=>"1"},
"key"=>"XXXXXXX(hidden for security"}
Current user: user1 (id=65)
Completed 500 Internal Server Error in 367ms (ActiveRecord: 19.9ms)
NoMethodError (undefined method `shared_versions' for nil:NilClass):
  app/models/issue.rb:823:in `assignable_versions'
  app/models/issue.rb:643:in `validate_issue'
  app/controllers/issues_controller.rb:141:in `create'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'

所以,我尝试使用Web浏览器(IE11)创建新的issew。 票证是正常创建的。这是production.log。

Started POST "/redmine/projects/mt001/issues" for XX.XX.XX.XXX at 2016-05-30 14:58:23 +0900
Processing by IssuesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"QF1BA5MgwysJsAiFfT/h95DeZ/VgzSGOnryR6xUn4mmWpf7EZ8XFJqpaye/ZLXrKR/wV00dKOz8KbhP94VcUyg==", "form_update_triggered_by"=>"",     "issue"=>{"tracker_id"=>"6", "subject"=>"Test2", "description"=>"This is test", "status_id"=>"1", "priority_id"=>"2", "assigned_to_id"=>"4", "category_id"=>"132", "fixed_version_id"=>"127", "parent_issue_id"=>"", "start_date"=>"2016-05-30", "due_date"=>"2016-06-03", "custom_field_values"=>{"12"=>"", "41"=>""}}, "was_default_status"=>"1", "commit"=>"create", "project_id"=>"mt001"}
  Current user: user1 (id=65)
  Rendered mailer/_issue.text.erb (7.1ms)
  Rendered mailer/issue_add.text.erb within layouts/mailer (9.8ms)
  Rendered mailer/_issue.html.erb (3.0ms)
  Rendered mailer/issue_add.html.erb within layouts/mailer (5.1ms)
Redirected to http://mydepartment.co.jp/redmine/issues/1717
Completed 302 Found in 3697ms (ActiveRecord: 130.3ms)

我已经尝试过迁移,清除缓存。 我接下来该怎么做。

这是我在RHEL7.2上的环境

Environment:
  Redmine version                3.2.0.stable
  Ruby version                   2.2.4-p230 (2015-12-16) [x86_64-linux]
  Rails version                  4.2.5
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.7.14
  Git                            1.8.3.1
  Filesystem                     
Redmine plugins:
  redmine_export_with_journals   0.0.8
  redmine_importer               1.2.2
  redmine_local_avatars          1.0.0
  redmine_xlsx_format_issue_exporter 0.1.2
  sidebar_hide                   0.0.7

这是assinable_versions源代码

# Versions that the issue can be assigned to
def assignable_versions
  return @assignable_versions if @assignable_versions

  versions = project.shared_versions.open.to_a #Here is line823

  if fixed_version
    if fixed_version_id_changed?
      # nothing to do
    elsif project_id_changed?
      if project.shared_versions.include?(fixed_version)
        versions << fixed_version
      end
    else
      versions << fixed_version
    end
  end
  @assignable_versions = versions.uniq.sort
end

2 个答案:

答案 0 :(得分:0)

发生错误是因为project为nil并且您正在尝试调用nil.shared_versions。所以改变if条件:

if !project.shared_versions.nil? 
  versions = project.shared_versions.open.to_a 
end 

如下:

versions = project.shared_versions.open.to_a unless project.nil?

这将解决'未定义的方法'错误。

答案 1 :(得分:0)

我已经解决了问题。 REST过程有一些不同。

至少redmine 2.4.4,我可以同时使用project_id = identifier和project_id = project_id进行创建。

但是,redmine 3.x,我只能使用project_id = project_id进行问题创建。