mattn / go-redmine

MIT License
185 stars 80 forks source link

Fix issue creation with nil custom_fields #13

Closed tbaud0n closed 8 years ago

tbaud0n commented 8 years ago

Trying to create an issue using the lib with the following code :

var issue redmine.Issue

issue.ProjectId = 1
issue.Subject = "Subject"
issue.Description = "Description"

c := redmine.NewClient(endpoint, apikey)
_, err := c.CreateIssue(issue) 

Redmine returns an error 500 and there's en entry in the log :

NoMethodError (undefined method `inject' for nil:NilClass):
  lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb:54:in `custom_fields='
  app/models/issue.rb:358:in `assign_attributes_with_project_and_tracker_first'
  app/models/issue.rb:483:in `safe_attributes='
  app/controllers/issues_controller.rb:444:in `build_new_issue_from_params'

The problem is that the custom_fields key must not be in the JSON if its value is nil or empty.

I've only added the tag omitempty to the custom_fields attribute so it's not added in the JSON if its value is empty

mattn commented 8 years ago

Thank you