racktables_api icon indicating copy to clipboard operation
racktables_api copied to clipboard

can not add attributes to a racktables object

Open MrMarvin opened this issue 11 years ago • 1 comments

We are running RackTables version 0.20.8 and racktables_api 0d902a7f8b1 with mixed success. Querying data (all GET requests) works fine, however, doing POST and PATCH requests we are experiencing weird behavior!

What we do:

2.1.2 :213 > HTTParty.patch(url+"/43", :body => JSON.dump("attributes"=>{"FQDN"=>"www.example.com"}) ,:basic_auth => {:username => URI.parse(url).user, :password => URI.parse(url).password})
 => #<HTTParty::Response:0x1010bb088 parsed_response={"updated"=>1}, @response=#<Net::HTTPOK 200 OK readbody=true>, @headers={"content-type"=>["application/json"], "transfer-encoding"=>["chunked"], "connection"=>["close"]}>

and the (debug) log of racktables_api is the following:

D, [2014-11-06T18:47:31.036568 #30137] DEBUG -- statsd: user_agent.unknown 1 c
D, [2014-11-06T18:47:31.036862 #30137] DEBUG -- addressive-router: [ ? ] url: "racktables.example.com:9292/object/43", path: "/object/43"
Exception `Sequel::Rollback' at /home/marfri/.rvm/gems/ruby-2.1.2/gems/sequel-4.7.0/lib/sequel/database/transactions.rb:115 - Sequel::Rollback
D, [2014-11-06T18:47:31.045850 #30137] DEBUG -- statsd: resources.object.actions.single.PATCH.inner_time 8.139602 ms
D, [2014-11-06T18:47:31.046026 #30137] DEBUG -- statsd: resources.object.actions.single.PATCH.count 1 c
D, [2014-11-06T18:47:31.046185 #30137] DEBUG -- addressive-router: [200] /object/{id} with {"id"=>"43"} on <Logistician::Repository::SingleResource for <Logistician::Sequel::Repository model: Model::RackObject>> ( route 11 / 18 ) after 0.000317
D, [2014-11-06T18:47:31.046337 #30137] DEBUG -- statsd: resources.object.actions.single.PATCH.total_time 10.890201000000001 ms
172.16.4.227 - - [06/Nov/2014 18:47:31] "PATCH /object/43 HTTP/1.1" 200 - 0.0133

However, the attribute is never inserted into the database!

As this is not the only problem we're seeing here, I could image that we do have a version mismatch here. Which versions are supported / tested?

MrMarvin avatar Nov 06 '14 18:11 MrMarvin

https://github.com/xing/racktables_api/blob/master/lib/logistician/repository/single_resource.rb#L32

With

      DB.transaction do
        updates = repository.single_update(ctx, input, objects )
        ups = updates.do!
      end

(omitting the rollback)

it works.

Cheers

timbru31 avatar Nov 24 '14 16:11 timbru31