Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

NoMethodError for LookerSDK::Client #82

Open
cionescu opened this issue Jan 15, 2019 · 9 comments
Open

NoMethodError for LookerSDK::Client #82

cionescu opened this issue Jan 15, 2019 · 9 comments

Comments

@cionescu
Copy link

Hello,

I noticed some strange behavior with the client sdk.

I am configuring the client as:

  def client
    @_client ||= LookerSDK::Client.new(
      client_id: Settings.looker.client_id,
      client_secret: Settings.looker.client_secret,
      api_endpoint: Settings.looker.api_endpoint,
      connection_options: {
        request: {
          timeout: 360,
          open_timeout: 30,
        },
      },
    )
  end

when using the client, I sometimes get

NoMethodError: undefined method run_inline_query' for #<LookerSDK::Client:0x0000000130cbd0> from looker-sdk/client/dynamic.rb:62:in method_missing'

I have not been able to find a better stack trace for this (even adding breakpoints in your client was not enough to figure this out). I was able to narrow down the failure to this test case:

    it "throws an error" do
      stub_request(:post, /caring.looker.com:19999\/login/).to_return(status: [500, "Internal Server Error"])
      stub_request(:get, /caring.looker.com:19999\/api\/3.0\/swagger.json/).to_return(status: [500, "Internal Server Error"])

      expect {
        client.run_inline_query('json', {})
      }.to raise_exception(NoMethodError)
    end

How should I handle this? My understanding is that a 500 during the login or when fetching swagger.json would make @swagger be nil, propping find_entry(method_name) in dynamic.rb return false. The 500 during either the login or fetching the config json is something to be expected, but I would expect a LookerSDK::ServerError instead of a NoMethodError

@dthorpe
Copy link
Contributor

dthorpe commented Jan 16, 2019

Thanks for logging this issue. I'll be investigating this in more detail, but my best guess right now is that the swagger.json is failing to download for some reason, and the client sdk isn't handling that case well. Beefing up the error reporting in this area will be my first step.

@cionescu
Copy link
Author

Thanks for this @dthorpe. Do you have any update on this?

@dthorpe
Copy link
Contributor

dthorpe commented Jan 27, 2019

@cionescu

HTTP 500 Server Error is not an error to be expected from login or swagger.json. Please check the Looker instance's admin logs for 500 Server Error log entries. These log entries should contain stack traces. If you find such entries in the logs, please copy them into a message here to help me better understand what's failing.

I've added some diagnostic messages to the client sdk in this PR: #83
If you could pull that branch to your local disk and try running your code using this modified sdk, please let me know if you see error messages reported by the client sdk for try_load_swagger. Again, for any API error response seen on the client there should be a corresponding entry in the Looker admin logs, and a copy of those would be very helpful.

Thanks,
-Danny

@dthorpe
Copy link
Contributor

dthorpe commented Jan 27, 2019

@cionescu
Do you ever set sdk.shared_swagger to true? It defaults to false. When set to true, it changes the way the client loads the swagger metadata.

@cionescu
Copy link
Author

cionescu commented Jan 30, 2019

Hi @dthorpe. Thanks for looking into this.

  1. I am not sure how to check the Looker instance admin logs.
  2. Do you have any idea when will your PR make it into a new gem release? I'd like to upgrade our client and perhaps monitor our application logs for that message
  3. I never set the shared_swagger config, so I'm assuming it's still false. An overview of the way I'm using the client is:
def client
    @_client ||= LookerSDK::Client.new(
      client_id: Settings.looker.client_id,
      client_secret: Settings.looker.client_secret,
      api_endpoint: Settings.looker.api_endpoint,
      connection_options: {
        request: {
          timeout: 360,
          open_timeout: 30,
        },
      },
    )
end
# ... and then ..
client.run_inline_query("json", query).map(&:to_h) 

@dthorpe
Copy link
Contributor

dthorpe commented Jan 31, 2019

Hi @cionescu thanks for the follow-up. Your code looks fine.

The Looker instance admin logs can be found in the Looker web app under the Admin menu. Scroll all the way to the bottom and select Log, under the Server section header. If you don't have admin rights, ask your Looker admin to view the log with you. It will help to have the log window open while you run your API script.

@cionescu
Copy link
Author

cionescu commented Jun 5, 2019

@dthorpe did you make any progress with this?

@OAuthBringer
Copy link

I'm working with the looker-sdk right now and am writing out specs for an implementation that configures users, groups, and permissions for use with embedding.

What I can say in the little time I've been using the SDK is that the no_method_error can be caused by a few things including failure to connect to the looker host. If the host is not available you can still initialize the client, but that doesn't mean your connection was successful.

If you try to execute a dynamically created method with a bad host connection it will fail to load the swagger json and throw the no_method_error.

One suggestion I have is to try testing the host connection before running your dynamic method. i.e. sdk.client.alive should return a 200 if it is available.

I would advocate for better error handling overall as no_method_error simply implies that a swagger.json file has not been loaded.

@dsoegijono
Copy link

dsoegijono commented Oct 29, 2020

I'm seeing this error as well, when I think it should be an Unauthorized error (return by sdk.last_error)

2.5.3 :018 > sdk.update_session({ workspace_id: 'dev' })
Traceback (most recent call last):
        7: from /Users/daphne/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
        6: from /Users/daphne/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
        5: from /Users/daphne/.rvm/gems/ruby-2.5.3/bin/irb:23:in `<main>'
        4: from /Users/daphne/.rvm/gems/ruby-2.5.3/bin/irb:23:in `load'
        3: from /Users/daphne/.rvm/gems/ruby-2.5.3/gems/irb-1.2.7/exe/irb:11:in `<top (required)>'
        2: from (irb):18
        1: from /Users/daphne/.rvm/gems/ruby-2.5.3/gems/looker-sdk-0.0.7/lib/looker-sdk/client/dynamic.rb:105:in `method_missing'
NoMethodError (undefined method `update_session' for #<LookerSDK::Client:0x00007fb14619a5d8>)
2.5.3 :019 > sdk.last_error
 => #<LookerSDK::Unauthorized: GET https://mycompany.looker.com/api/3.0/swagger.json: 401 - Error: Unauthorized>

sdk.alive returns 200

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

No branches or pull requests

4 participants