Rails 5.2, Ruby 2.5.9, serialization and unknown keywords: permitted_classes, aliases

I wrote here few times here about quirks working with older Rails application. For example, upgrading old app to some more up-to-date toolset can be challenging. In my opinion it is best done step by step, so having 4.0 Rails app it is much more challenging to upgrade right to 6.1 will be very hard. So I suggest going step by step. Read release notes for Rails versions and do try to guess what steps are safe for Your application.

Recently I did 4.0 -> 4.2 -> 5.0 -> 5.2 and probably will be 6.1 next in order, but… We are now on 5.2. With Ruby upgraded to 2.5.9 (BTW good table with info which Ruby and Rails are compatible) and Rails in 5.2 I have experienced errors unknown keywords: permitted_classes, aliases. It is related to serialization (some data was stored in ActiveRecord that way using Psych gem. But You can not find Psych on gems list. It is bundled with Ruby and used if not provided with alternative.

So, just add Psych to Your gem file with correct version. Bundled version with 2.5.9 is Psych 3.0.6, using Psych 5.x or 4.x resulted in other problems/errors so I have finally settled with gem 'psych', '~> 3.3'which ended with 3.3.4 installed. Now everything works, I can move with updating app further.

In case you are storing hash with symbols as key, then doing deserialization you may encounter Tried to load unspecified class: Symbol. In that case add to initializers: config.active_record.yaml_column_permitted_classes = [Symbol]

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.