Defect #6403
Updating an issue with custom fields fails
| Status: | Closed | Start date: | 2010-09-15 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | Jean-Philippe Lang | % Done: | 0% |
|
| Category: | REST API | |||
| Target version: | 1.1.0 | |||
| Affected version: | 1.0.4 | Resolution: | Fixed |
Description
If I run the following code
1require 'rubygems'
2require 'active_resource'
3
4# Issue model on the client side
5class Issue < ActiveResource::Base
6 self.site = 'http://redmine.server/'
7 self.user = 'foo'
8 self.password = 'bar'
9end
10
11# Updating an issue
12issue = Issue.find(1)
13issue.subject = 'REST API'
14issue.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
1# Updating an issue
2issue = Issue.find(1)
3issue.subject = 'REST API'
4issue.custom_fields = nil
5issue.save
it works !
Related issues
Associated revisions
Fixed: error when serializing back objects with custom fields using ActiveResource (#6403).
History
#1 Updated by Ward Vandewege over 1 year ago
I can confirm this - I'm seeing the same thing. It's the custom_fields that cause this.
#2 Updated by Stéphane Dubois over 1 year ago
Something strange:
to create an issue with a custom field we do
1issue = Issue.new(
2 :subject => 'REST API',
3 :assigned_to_id => 1,
4 :project_id => 1,
5 :custom_field_values => {'2' => 'Fixed'}
6)
7issue.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
1issue = Issue.find(1)
2issue.custom_fields.custom_field[0] = dummy_value
3issue.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.
#3 Updated by Stéphane Dubois over 1 year ago
In fact, it's possible to update a custom fields with the same hash than for creation, but you must also nilify custom_fields
1issue = Issue.find(1)
2issue.custom_field_values = {'1' => 'dummy'}
3issue.custom_fields = nil
4issue.save
#4 Updated by Eric Davis over 1 year ago
- Assignee set to Eric Davis
#5 Updated by Eric Davis over 1 year ago
- 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
#6 Updated by Jean-Philippe Lang over 1 year ago
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:
1issue = Issue.find(1)
2issue.custom_field_values = {'1' => 'dummy'}
3issue.save
#7 Updated by Jean-Philippe Lang over 1 year ago
- Assignee set to Jean-Philippe Lang
- Target version set to 1.0.5
- Affected version set to 1.0.4
Problem found. The fix requires a slight change in the custom fields part of the API.
#8 Updated by Jean-Philippe Lang over 1 year ago
- Status changed from New to Resolved
- Resolution set to Fixed
#9 Updated by Jean-Philippe Lang over 1 year ago
- 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.