Defect #6403
closed
Updating an issue with custom fields fails
Added by Stéphane Dubois about 14 years ago.
Updated almost 14 years ago.
Description
If I run the following code
require 'rubygems'
require 'active_resource'
# Issue model on the client side
class Issue < ActiveResource::Base
self.site = 'http://redmine.server/'
self.user = 'foo'
self.password = 'bar'
end
# Updating an issue
issue = Issue.find(1)
issue.subject = 'REST API'
issue.save
it fails on issue.save with the following error
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/array/conversions.rb:163:in `to_xml': Not all elements respond to to_xml (RuntimeError)
I suspect it has something to do with custom fields because if I do
# Updating an issue
issue = Issue.find(1)
issue.subject = 'REST API'
issue.custom_fields = nil
issue.save
it works !
I can confirm this - I'm seeing the same thing. It's the custom_fields that cause this.
Something strange:
to create an issue with a custom field we do
issue = Issue.new(
:subject => 'REST API',
:assigned_to_id => 1,
:project_id => 1,
:custom_field_values => {'2' => 'Fixed'}
)
issue.save
but when I retrieve an issue with REST API, :custom_field_values is not an entry of the attributes hash. Instead, I have a :custom_fields entry containing a custom_field entry which is an array containing all custom fields values.
If a try to update one of those values like that
issue = Issue.find(1)
issue.custom_fields.custom_field[0] = dummy_value
issue.save
I get the same error
C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/array/conversions.rb:163:in `to_xml': Not all elements respond to to_xml (RuntimeError)
So, I can't find a way to update a custom field.
In fact, it's possible to update a custom fields with the same hash than for creation, but you must also nilify custom_fields
issue = Issue.find(1)
issue.custom_field_values = {'1' => 'dummy'}
issue.custom_fields = nil
issue.save
- Assignee set to Eric Davis
- Assignee deleted (
Eric Davis)
I am stepping down from working on Redmine. If someone else is interesting in working on this issue, feel free to reassign it to them.
Eric Davis
Stéphane Dubois wrote:
In fact, it's possible to update a custom fields with the same hash than for creation, but you must also nilify custom_fields
[...]
I don't know which version you're using but I can't reproduce this problem with current trunk. The following works:
issue = Issue.find(1)
issue.custom_field_values = {'1' => 'dummy'}
issue.save
- Assignee set to Jean-Philippe Lang
- Target version set to 1.0.5
- Affected version (unused) set to 1.0.4
- Affected version set to 1.0.4
Problem found. The fix requires a slight change in the custom fields part of the API.
- Status changed from New to Resolved
- Resolution set to Fixed
Problem is fixed in r4480, r4481. You can now the custom_fields array received in the API response to update custom_fields.
issue = Issue.find(6467)
issue.custom_fields.first.name # => "Affected version"
issue.custom_fields.first.value = '1.0.3'
issue.save
- Status changed from Resolved to Closed
- Target version changed from 1.0.5 to 1.1.0
It will have to wait 1.1.0 because it relies on changes done in trunk only.
Also available in: Atom
PDF