0

I'm troubled with redmine.

When I create new issue with Rest API(from Microsoft Excel), Internal Error 500 happened. Seeing from production.log, "NoMethodError" is happened (see below message)

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'

So, I tried to create new issew using web browser (IE11). The ticket was created normally. Here is 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)

I already tried to migrate, clear cache. What should I do next.

Here is my environment on 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

Here is assinable_versions source-code

# 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
  • The error is occurring in app/models/issue.rb where you are calling 'shared_versions' method with an object of nil class. Check your app/models/issue.rb at line number 823. – Prity May 31 '16 at 08:02
  • Thanks Prity! Of cource I've checked at line 823 on issue.rb. – Tomoya Katsuki Jun 01 '16 at 01:47
  • Here is the code. **#Versions that the issue can be assigned to def assignable_versions versions = project.shared_versions.open.to_a (<- line 823)** And then I've checked project.rb, "def shared_versions" exist. After that I add nil judgement before line 823 of issue.rb. , like this. **# Add Nil Judgement if !project.shared_versions.nil? versions = project.shared_versions.open.to_a end** But same error happens on nil judgment line. – Tomoya Katsuki Jun 01 '16 at 01:56
  • Thanks, here ls source code. ` # 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` – Tomoya Katsuki Jun 06 '16 at 06:50

2 Answers2

0

The error is occurring because project is nil and you are trying to call nil.shared_versions. So change the if condition:

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

to as follows:

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

This will resolve the 'undefined method' error.

Prity
  • 224
  • 1
  • 7
  • Thanks! I've changed Nil judgement as you said. The "undefined method error" at line 823 is disappeared! But trouble has been continued. – Tomoya Katsuki Jun 02 '16 at 12:20
  • @Tomoya Katsuki I think you should check your code that why project = nil ? Please share complete code of 'assignable_versions' method in issue.rb – Prity Jun 02 '16 at 12:24
  • Thanks @Prity. Please see original Question text. I added assignable_version source code. – Tomoya Katsuki Jun 08 '16 at 01:14
0

I've solved problem. There is some difference of REST process.

At least redmine 2.4.4, I can use both project_id = identifier and project_id = project_id for issue create.

But, redmine 3.x, I can only use project_id = project_id for issue create.