mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.98k stars 1.19k forks source link

ActsAsTaggableOn.force_binary_collation breaks db:create #905

Open dvmonroe opened 6 years ago

dvmonroe commented 6 years ago

Versions ActsAsTaggableOn: 6.0 Rails: 5.2 Ruby: 2.4.2

Steps to reproduce

$ rails new Foobar -d mysql
$ cd Foobar && echo "ActsAsTaggableOn.force_binary_collation = true" > config/initializers/acts_as_taggable_on.rb && echo 'gem "acts-as-taggable-on"' >> Gemfile
$ bundle
$ rails db:create

Expected Behavior Able to successfully run rails db:create.

Actual Behavior Utils.connection is blindly expecting an AR connection leaving the end user no choice but to wrap the initializer in a conditional that rescues from ActiveRecord::NoDatabaseError.

rails aborted!
ActiveRecord::NoDatabaseError: Unknown database 'foobar_development'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/mysql2_adapter.rb:26:in `rescue in mysql2_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/mysql2_adapter.rb:13:in `mysql2_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:809:in `new_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `checkout_new_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:832:in `try_to_checkout_new_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:793:in `acquire_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:521:in `checkout'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:380:in `connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:1008:in `retrieve_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:90:in `connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/acts-as-taggable-on-6.0.0/lib/acts_as_taggable_on/utils.rb:8:in `connection'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/acts-as-taggable-on-6.0.0/lib/acts_as_taggable_on/utils.rb:16:in `using_mysql?'
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/acts-as-taggable-on-6.0.0/lib/acts-as-taggable-on.rb:94:in `force_binary_collation='
/Users/plu/.rbenv/versions/2.4.2/gemsets/foobar/gems/acts-as-taggable-on-6.0.0/lib/acts-as-taggable-on.rb:50:in `method_missing'
/Users/plu/Projects/work/foobar/config/initializers/acts_as_taggable.rb:24:in `<top (required)>
saluminati commented 5 years ago

wasted so much of my time. any solution to this ?

shuuuuun commented 4 years ago

Provisionally, I've solved it this way in config/initializers/acts_as_taggable_on.rb.

begin
  ActsAsTaggableOn.force_binary_collation = true
rescue ActiveRecord::NoDatabaseError => err
  Rails.logger.error err
end

I hope that this issue will be fixed.

tbuyle commented 2 years ago

Faced this issue today.

@shuuuuun workaround solved it for me.