visoft / ruby_odata

OData Consumer for Ruby
http://bit.ly/IntroRubyOData
MIT License
107 stars 52 forks source link

build_function_imports undefined method `content' #61

Closed luckyraul closed 8 years ago

luckyraul commented 8 years ago

Got exception: undefined method `content' for nil:NilClass

<?xml version="1.0" encoding="UTF-8"?>
<service xmlns="http://www.w3.org/2007/app"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xml:base="http://ip/odata/standard.odata">
    <workspace>
        <atom:title>Default</atom:title>
        <collection href="Catalog_Номенклатура">
            <atom:title>Catalog_Номенклатура</atom:title>
        </collection>
...
NoMethodError: undefined method `content' for nil:NilClass
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:244:in `block in build_function_imports'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.2/lib/nokogiri/xml/node_set.rb:186:in `each'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:243:in `build_function_imports'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:236:in `build_collections_and_classes'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:20:in `initialize'
visoft commented 8 years ago

Can you provide me with the full EDMX and the Results XML? With these I should be able to generate a failing test to help me sort out this issue.

Sorry for the delayed reply, I was on vacation.

luckyraul commented 8 years ago

https://www.dropbox.com/s/9ej7u7h7tj2c43a/standard.odata.xml?dl=1

visoft commented 8 years ago

Is that the result of the call to http://myServer.com/myService.svc/$metadata (obviously replacing myServer and myService)? Also, what version of OData are you using?

luckyraul commented 8 years ago

https://www.dropbox.com/s/4ttsfc1j92jzau7/metadata.xml?dl=1

visoft commented 8 years ago

Thank you for that. When do you get the error? It seems to parse the EDMX ok, so you must be peforming a query?

luckyraul commented 8 years ago

Just created OData::Service.new object with url, nothing more

visoft commented 8 years ago

This test is passing on my machine using your EDMX:

    describe "properly parse build function import" do
      before(:each) do
        # Required for the build_classes method
        stub_request(:get, "http://test.com/test.svc/$metadata").
          with(:headers => DEFAULT_HEADERS).
          to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/build_function_imports/bfi_metadata.xml", __FILE__)), :headers => {})
      end

      it "should not error with 'undefined method `content' for nil:NilClass'" do
        lambda { OData::Service.new "http://test.com/test.svc" }.should_not raise_error
      end
    end
visoft commented 8 years ago

I just tried it using 0.1.6 in irb. OData::Service.new works fine. I'm using Ruby 2.2.2, but I don't think that could be the issue, though you never know. What version of Ruby are you using?

luckyraul commented 8 years ago
x=Document.create_in_1c
NoMethodError: undefined method `content' for nil:NilClass
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:244:in `block in build_function_imports'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.3/lib/nokogiri/xml/node_set.rb:187:in `block in each'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.3/lib/nokogiri/xml/node_set.rb:186:in `upto'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.3/lib/nokogiri/xml/node_set.rb:186:in `each'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:243:in `build_function_imports'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:236:in `build_collections_and_classes'
    from /Users/nikita/.rvm/gems/ruby-2.2.3/gems/ruby_odata-0.1.0/lib/ruby_odata/service.rb:20:in `initialize'
    from /Volumes/Data/GIT/projects/mygento/account/app/models/document.rb:5:in `new'
luckyraul commented 8 years ago

I guess You didn't push release to ruby gems so I use 0.1.0

visoft commented 8 years ago

Let me fix that.

visoft commented 8 years ago

0.1.6 is out there https://rubygems.org/gems/ruby_odata

luckyraul commented 8 years ago

I see, but my Gemfile is not strict on any version of your gem. I'll try to check

luckyraul commented 8 years ago
Bundler could not find compatible versions for gem "i18n":
  In Gemfile:
    rails (~> 4.2) ruby depends on
      activejob (= 4.2.0) ruby depends on
        activesupport (= 4.2.0) ruby depends on
          i18n (~> 0.7) ruby

    ruby_odata (= 0.1.6) ruby depends on
      i18n (~> 0.6.0) ruby
visoft commented 8 years ago

I don't have any lock on i18n:

  s.add_dependency("addressable", ">= 2.3.4")
  s.add_dependency("i18n", ">= 0.7.0")
  s.add_dependency("activesupport", ">= 3.0.0")
  s.add_dependency("rest-client", ">= 1.5.1")
  s.add_dependency("nokogiri", ">= 1.4.2")
luckyraul commented 8 years ago

No, You have https://rubygems.org/gems/ruby_odata

visoft commented 8 years ago

Hmm, that's odd. Let me see if I can fix that.

visoft commented 8 years ago

Released a new version, 0.2.0,beta1. We changed to Faraday instead of RestClient so I want to make sure people have time to test it out and make sure it doesn't break, hence the beta1. This will hopefully fix your issue as it worked fine for me.

luckyraul commented 8 years ago

Great, No errors on connection. In addition can you help me - how to call cyrillic collection (for ex "Catalog_Банки") ?

visoft commented 8 years ago

Great!

Assuming it properly parses the names (which it seems to in my tests), it should just be something like this:

svc = OData::Service.new 'http://95.213.158.5/hamster/odata/standard.odata'
svc.Catalog_Банки
results = svc.execute
puts results.to_json
luckyraul commented 8 years ago

thanks a lot

rkachowski commented 8 years ago

Also receive the same error - but when using 0.2.0.beta1 I can progress (another error but more informative).

Using ruby 2.3.0 on osx fwiw

visoft commented 8 years ago

@rkachowski What's the error?

rkachowski commented 8 years ago

I don't have time to look into it now, but I believe it's an error due to the server not sending the correct data (using artifactory's odata feed) - i.e. it's not an error from the gem