yolk/valvat

Valvat::Lookup.validate always returns nil in Ruby 2.2.0

mrrooijen opened this issue · 17 comments

Valvat::Lookup.validate(vat_number)

Always returns nil instantly (seems like it isn't performing a network operation). It does appear to work properly in Ruby 2.1.5 but not in the latest Ruby 2.2.0-preview2.

yolk commented

Hi @meskyanichi,
thanks for your report & sorry for the delayed answer.

I couldn't reproduce the problem with ruby 2.2.0-preview2 (locally and with travis). Could you please provide the versions of valvat and savon you are using? I guess it could be related to an older version of savon (the lib valvat uses to handle the SOAP-stuff).

Thx,
Sebastian.

Hi Sebastian,

Apparently it works now that I add it to a Gemfile. When I create a blank file with simple the above it returns nil. When I create a Gemfile and lock it with:

  * akami (1.2.2)
  * builder (3.2.2)
  * bundler (1.7.3)
  * gyoku (1.2.2)
  * httpi (2.3.0)
  * macaddr (1.7.1)
  * mime-types (1.25.1)
  * mini_portile (0.6.1)
  * nokogiri (1.6.5)
  * nori (2.4.0)
  * rack (1.5.2)
  * savon (2.8.0)
  * systemu (2.6.4)
  * uuid (2.3.7)
  * valvat (0.6.7)
  * wasabi (3.3.0)

Then for some reason it does perform the validation check. It might've been including an invalid dependency version or something.

yolk commented

Hi Michael,
thx for the details. I tried to reproduce the problem with older version (2.3) of savon, but it all worked flawlessly. If you re still interested in fidning the issue, could you check the used versions in the failing script? Ala:

p [Valvat::VERSION, Savon::VERSION]

This combination was used:

nil # the failing request
["0.6.7", "2.8.0"]

My environment is bundled though, I was just experimenting in IRB prior to adding it to see how/if it works for me. :)

Same issue with ruby 2.0.0-p195 works fine:

>> Valvat::Checksum.validate("DE345789003")
=> false
>> p [Valvat::VERSION, Savon::VERSION]
["0.6.8", "2.9.0"]

buy with ruby 2.1.5 returns nil:

>> Valvat::Lookup.validate("DE345789003")
=> nil
>> p [Valvat::VERSION, Savon::VERSION]
["0.6.8", "2.9.0"]

@byterussian make sure the services you are trying to check is working: http://ec.europa.eu/taxation_customs/vies/technicalInformation.html

Also you can pass :raise_error option: https://github.com/yolk/valvat/blob/master/lib/valvat/lookup.rb#L22

@dmitry Service is working. If I set :raise_error see:

RuntimeError: eventmachine not initialized: evma_connect_to_server
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/eventmachine-1.0.4/lib/eventmachine.rb:673:in `connect_server'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/eventmachine-1.0.4/lib/eventmachine.rb:673:in `bind_connect'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/em-http-request-1.1.2/lib/em-http/http_connection.rb:55:in `activate_connection'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/em-http-request-1.1.2/lib/em-http/http_connection.rb:92:in `setup_request'
    from (eval):6:in `get'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/httpi-2.3.0/lib/httpi/adapter/em_http.rb:50:in `block in request'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/httpi-2.3.0/lib/httpi/adapter/em_http.rb:68:in `_request'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/httpi-2.3.0/lib/httpi/adapter/em_http.rb:50:in `request'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/httpi-2.3.0/lib/httpi.rb:159:in `request'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/httpi-2.3.0/lib/httpi.rb:125:in `get'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/wasabi-3.3.0/lib/wasabi/resolver.rb:43:in `load_from_remote'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/wasabi-3.3.0/lib/wasabi/resolver.rb:33:in `resolve'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/wasabi-3.3.0/lib/wasabi/document.rb:142:in `xml'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/wasabi-3.3.0/lib/wasabi/document.rb:160:in `parse'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/wasabi-3.3.0/lib/wasabi/document.rb:147:in `parser'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/wasabi-3.3.0/lib/wasabi/document.rb:64:in `soap_actions'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/savon-2.9.0/lib/savon/operation.rb:22:in `ensure_exists!'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/savon-2.9.0/lib/savon/operation.rb:15:in `create'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/savon-2.9.0/lib/savon/client.rb:32:in `operation'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/savon-2.9.0/lib/savon/client.rb:36:in `call'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/valvat-0.6.8/lib/valvat/lookup/request.rb:9:in `perform'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/valvat-0.6.8/lib/valvat/lookup.rb:43:in `response'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/valvat-0.6.8/lib/valvat/lookup.rb:39:in `valid?'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/valvat-0.6.8/lib/valvat/lookup.rb:19:in `validate'
    from /Users/byterussian/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/valvat-0.6.8/lib/valvat/lookup.rb:28:in `validate'
    from (irb):2
    from /Users/byterussian/.rbenv/v

@dmitry Maybe is useful: In 2.0.0 env I don't have eventmachine and em-http-request gems installed and works.

@byterussian eventmachine/eventmachine#430

What versions of savon, wasabi and httpi do you have in both environments?

2.0.0-p195:

httpi (2.3.0)
savon (2.9.0)
wasabi (3.3.0)

2.1.5:

httpi (2.3.0)
savon (2.9.0)
wasabi (3.3.0)

same version

Update: After I've uninstalled eventmachine and em-http-request gems works even with 2.1.5.

@dmitry See the load order https://github.com/savonrb/httpi/blob/master/lib/httpi/adapter.rb#L16

If you add :httpclient or :curb gems as dependency in gemspec this does not occur.

I can send you a pull request?

@byterussian but what do you want to change in PR?
Do you have the same Gemfile.lock in your project for 2.0.0 and 2.1.5?

I had the same problem. I had to add rubyntlm to my Gemfile.

quinn commented

for me HTTPI::Adapter::Excon was incompatible with the version of excon i had bundled. updating the bundled version fixed this.

quinn commented

maybe the rescue on this line should be selective? https://github.com/yolk/valvat/blob/master/lib/valvat/lookup.rb#L20

only rescuing errors from timeouts or error http status codes

yolk commented

In the current master the rescue is much more selective. Closing.