Vote #68134
完了Updating an issue with custom fields fails
0%
説明
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 !
journals
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
<pre><code class="ruby">
issue = Issue.new(
:subject => 'REST API',
:assigned_to_id => 1,
:project_id => 1,
:custom_field_values => {'2' => 'Fixed'}
)
issue.save</code></pre>
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
<pre><code class="ruby">
issue = Issue.find(1)
issue.custom_fields.custom_field[0] = dummy_value
issue.save</code></pre>
I get the same error
<pre><code>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)</code></pre>
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
<pre><code class="ruby">issue = Issue.find(1)
issue.custom_field_values = {'1' => 'dummy'}
issue.custom_fields = nil
issue.save
</code></pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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:
<pre><code class="ruby">issue = Issue.find(1)
issue.custom_field_values = {'1' => 'dummy'}
issue.save
</code></pre>
--------------------------------------------------------------------------------
Problem found. The fix requires a slight change in the custom fields part of the API.
--------------------------------------------------------------------------------
Problem is fixed in r4480, r4481. You can now the custom_fields array received in the API response to update custom_fields.
<pre>
<code class="ruby">
issue = Issue.find(6467)
issue.custom_fields.first.name # => "Affected version"
issue.custom_fields.first.value = '1.0.3'
issue.save
</code>
</pre>
--------------------------------------------------------------------------------
It will have to wait 1.1.0 because it relies on changes done in trunk only.
--------------------------------------------------------------------------------
related_issues
relates,Closed,7377,Updating an Issue with custom fields set fails in V.1.1.0