ruby_odata icon indicating copy to clipboard operation
ruby_odata copied to clipboard

Error while try excecute update_object and save_changes

Open jdcrackdon opened this issue 13 years ago • 9 comments

Hi dude i have this code

svc = OData::Service.new "http://dev.idlinksolutions.com/clicktoaction/clicktoactionData.svc/" , { :username => "xxxxxxxxx", :password=> "xxxxxx" }

svc.FanPages.filter("PageId eq '#{settings.fan_page_id}'") fan_page = svc.execute.first

fan_page.Token = 'aaa'

svc.update_object(fan_page) result2 = svc.save_changes

p result2.inspect

But, this say Bad request 400 error

jdcrackdon avatar May 15 '12 20:05 jdcrackdon

Which part gives you a 400 error, the query portion of the update?

visoft avatar May 15 '12 21:05 visoft

result2 = svc.save_changes, in this line

jdcrackdon avatar May 15 '12 21:05 jdcrackdon

Try using the develop branch of ruby_odata. I added some basic error handling so you should be able to see the cause of your 400 error. It should spit out a more useful message (pulled from the error xml returned from the OData service) when the exception is thrown. Let me know what you find...

visoft avatar May 16 '12 01:05 visoft

Dude, look this is my error with the develop branch, i can not understand this: 2012-05-16T13:26:55+00:00 app[web.1]: RuntimeError - HTTP Error 400: <ExceptionInfo><Message>Only 'If-Match' headers are supported for Update/Delete operations.</Message></ExceptionInfo>:

i whan update a deatil table with a master. my table has a foreign key

jdcrackdon avatar May 16 '12 13:05 jdcrackdon

Is your OData Service using etags? I think it's a problem with concurrency management (scroll down to the section Concurrency Management here http://msdn.microsoft.com/en-us/library/ff798339.aspx). I'm not doing anything with passing etags around, so my guess is that the entity you are trying to update doesn't match the current entity.

visoft avatar May 16 '12 14:05 visoft

yes, i think this is the problem merge concurrency, with the etags.

jdcrackdon avatar May 17 '12 15:05 jdcrackdon

Hi - I've been stuck on the same problem for a few days. Can you share some code to illustrate how I can resolve this? From the link in the earlier post above it looks like I need to either:

  1. set the X-HTTP-Method header or
  2. indicate an ETag in the If-Match HTTP request header.

Im not sure how to do either on the odata service object. Here is my code:

svc_vm = OData::Service.new "https://server:8090/SC2012R2/vmm/Microsoft.Management.Odata.svc/", {:verify_ssl => false, :username => "user", :password => "password", :namespace => "VMM"}

svc_vm.VirtualMachines.Filter("Name eq 'LinuxVM'") vms = svc_vm.execute vm = vms.first vm.Operation = "Start" svc_vm.update_object(vm) result = svc_vm.save_changes

thanks in advance for any help.

bronaghs avatar Nov 19 '13 20:11 bronaghs

I haven't added support for etags, because I'm not sure how to set them up for an OData service. If you can figure it out and could supply sample data of returned results (edmx, and query results), then it should be something that ruby_odata could support.

visoft avatar Nov 20 '13 00:11 visoft

@jdcrackdon - Do you have some some sample code? i'm really stuck with this...

bronaghs avatar Nov 20 '13 17:11 bronaghs