Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User.shop throws a NilClass error without code change #146

Open
jetblackstar opened this issue Jan 11, 2023 · 0 comments
Open

User.shop throws a NilClass error without code change #146

jetblackstar opened this issue Jan 11, 2023 · 0 comments

Comments

@jetblackstar
Copy link

So on a system that has remained unchanged for months, this exception started coming up today.

I've not fully ruled out the user doing something but I don't think they could have broken this.

Getting the following exception on Console as an example. (validusername is obviously not a real username/id)

Etsy.user('validusername').shop

NoMethodError: undefined method `associated_shops' for nil:NilClass
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/etsy-0.3.3/lib/etsy/user.rb:80:in `shops'
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/etsy-0.3.3/lib/etsy/user.rb:46:in `shop'
        from (irb):12
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

Etsy.user('validusername') does return a valid Etsy::User response.

But looking into the code of the Etsy Gem,
etsy/user.rb;

          options = {:fields => 'user_id', :includes => 'Shops'}
          options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
          tmp = User.find(username, options)
          @shops = tmp.associated_shops.map { |shop| Shop.new(shop) }

Its tmp.associated_shops that is throwing the NilClass.
My guess is Shops is recently no longer is being allowed to include in the Etsy API? Or rather its just not returning a result to tmp in this query?

I've personally written around this issue by changing any calls of Etsy.user('validusername').shop to instead call Etsy::Shop.find('validshopid') which is probably a better way to directly access shop. But I wanted to flag this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant