There are two apps. One of the apps is using rails 4.1.2. The other app is using rails 5.0.1. Here is how the rails 5 app works: it checks if the user is logged in:
I am currently using the following gems in my Rails 5 project:
gem 'mysql2', '~> 0.4.4'
gem 'activerecord-session_store', '~> 1.0'
I then have the following in my config/initializers/session_store.rb
file:
Rails.application.config.session_store :active_record_store, :key => ‘SOME_KEY’
Currently: if the user is not logged in: then it successfully redirects the user. The issue is when the user is logged in. I get this error when the logged in user attempts to access the rails 5 app:
NameError (uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column)
sessions
table on initial request (when the user is not logged in).Any suggestions on what is triggering this error and how to fix it? Ultimately: it almost appears as though rails 5
is incompatible with activerecord-session_store
and mysql2
.
We were eventually able to figure it out.
The Marshal
module can serialize ruby objects to the database. It can also deserialize stuff from the database in order to recreate the objects.
When you serialize an object, there appears to be some low level info that goes in there too, like the mysql2 connection adapter.
When the Rails 5 app tries to deserialize the data, it throws this error because the constant that exists in the MySql2 connection adapter for Rails 4 does not exist in the Rails 5 version of that adapter.
Our work around was to just not store or retrieve any of the serialized objects from the sessions table for our rails 5 app. That did the trick.
If we had really needed to retrieve serialized objects from the sessions table for our rails 5 app: then I think we would have had to come up with a custom solution.
Hope this helps others in the future!
It may be due to changes in release i.e. Rails 5.0.
As In Ruby on Rails 5.0 Release Notes:
Removed support for the legacy mysql database adapter from core. Most users should be able to use mysql2. It will be converted to a separate gem when we find someone to maintain it.
Deprecated passing arguments to #tables - the #tables method of some adapters (mysql2, sqlite3) would return both tables and views while others (postgresql) just return tables. To make their behavior consistent, #tables will return only tables in the future.
Difference in constant as you described in your answer may be due to they going to change gem for mysql2 adapter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With