public-activity/public_activity

NameError: uninitialized constant PG

stuxcrystal opened this issue · 10 comments

If PublicActivity can't connect to a MySQL Database, it will fail with the following error:

NameError: uninitialized constant PG
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record/activity.rb:38:in `rescue in <class:Activity>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record/activity.rb:30:in `<class:Activity>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record/activity.rb:6:in `<module:ActiveRecord>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record/activity.rb:3:in `<module:ORM>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record/activity.rb:2:in `<module:PublicActivity>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record/activity.rb:1:in `<top (required)>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record.rb:2:in `require_relative'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/orm/active_record.rb:2:in `<top (required)>'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity.rb:51:in `inherit_orm'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/models/trackable.rb:6:in `included'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/common.rb:25:in `include'
  /home/deploy/webapps/WEBAPP/shared/bundle/ruby/2.3.0/gems/public_activity-1.6.3/lib/public_activity/common.rb:25:in `block in <module:Common>'

We are using Rails 4.2.11 with Public Activity 1.6.3.
It links to this file https://github.com/chaps-io/public_activity/blob/2c56992a61a1a6deaca92a66f7031e83a05c4e9a/lib/public_activity/orm/active_record/activity.rb#L40

Can you share your PublicActivity config? The one you probably have in initializers

I just checked, we do not have an initializer for PublicActivity. We are running ActiveRecord.

It looks to me that the actual error can't propagate out of the function as the uninitialized constant error is shadowing the actual error.

Mmm good catch, PG will not exist if the app is not using pg gem. This would probably need creating dummy PG constant and its exception when pg is not loaded.

You also need to do that with Mysql2::Error::ConnectionError two lines below as not all apps may use Mysql.

does it supports mongoid? I am getting uninitialized constant PG error

When would this merged in master branch..?

@zainonrails this has been released as 1.6.4. Can you try?

I don't merge to master, I use separate branches for each stable version.

@ashokmiryal it doesn't. Please post the exception you are getting or submit a PR which adds a clause for Mongoid exception in a similar way to how PG/Mysql are handled: 83d1406

So upgrading the gem would also solve this as right now i am using 1.6.3 branch in my gemfile.

@zainonrails then upgrade to 1.6.4. It's released :) Unless I missunderstood you.