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

NoMethodError (undefined method `post' for nil:NilClass) #15

Closed
ihenvyr opened this issue Jun 3, 2014 · 7 comments
Closed

NoMethodError (undefined method `post' for nil:NilClass) #15

ihenvyr opened this issue Jun 3, 2014 · 7 comments

Comments

@ihenvyr
Copy link

ihenvyr commented Jun 3, 2014

Hello,

"NoMethodError (undefined method `post' for nil:NilClass)" shows only in production when the app executes Podio::Item.create, Podio::Search.in_app, etc. I tried to execute the same thing in the production console but it works. Same goes under development environment - the app works fine. My current setup below:

config/initializers/podio.rb
require 'rubygems'
require 'podio'
Podio.setup(:api_key => 'YOUR_API_KEY', :api_secret => 'YOUR_API_SECRET')
Podio.client.authenticate_with_credentials('YOUR_PODIO_ACCOUNT', 'YOUR_PODIO_PASSWORD')

Thanks,

Henry

@andreas
Copy link
Contributor

andreas commented Jun 3, 2014

Can you provide a backtrace please?

@danmaz74
Copy link

danmaz74 commented Jun 3, 2014

Hi Andreas

We found the reason of the problem, and why it worked in testing but not in production. We are doing the API setup in a initializers/podio.rb file, with

Podio.setup(:api_key => 'YOUR_API_KEY', :api_secret => 'YOUR_API_SECRET')
Podio.client.authenticate_with_credentials('YOUR_PODIO_ACCOUNT', 'YOUR_PODIO_PASSWORD')

Now, the problem is that in production we use Passenger (with Apache), and we discovered that the setup is only done once when starting the server - not once for every process that Passenger spawns. And your client is somehow tied to the process itself, so, inside each passenger processes, Podio.client is actually nil

We did a quick fix by adding a before_filter to ApplicationController, and init the api if Podio.client.nil? , but this is very ugly. If you are aware of - or can find - any better solution to init the API only once, in a way that works with Passenger (which I think is used by 99% of Rails developers), that would be very useful :)

@andreas
Copy link
Contributor

andreas commented Jun 3, 2014

The gem uses thread local storage to store the current connection, which I think is causing what you're experiencing. This is mentioned briefly in the readme, but should probably be more explicit. We'll try think of a better solution -- thanks for bringing up the issue!

@andreas andreas closed this as completed Jun 3, 2014
@danmaz74
Copy link

danmaz74 commented Jun 3, 2014

Ok, please update us if you find one!

@jclay
Copy link

jclay commented Sep 9, 2015

Just ran into this issue as well. Thanks for the workaround @danmaz74

@f6v
Copy link

f6v commented May 19, 2016

Having the same issue when calling Podio in Sidekiq job. What's the best way to initialise library when using Sidekiq?

@cpeters
Copy link
Contributor

cpeters commented Jul 27, 2016

I haven't personally used Sidekiq but I did a quick scan of the docs. There is a mention that workers must be thread safe. It appears that you'd have to initialize a connection to the Podio Api within each worker.

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

6 participants