Tried to load unspecified class: ActiveSupport::TimeWithZone - Psych::DisallowedClass

6.2k Views Asked by At

Does anyone know how to fix this exception? Not sure if it's related but it is falling on #discard method calling from discard gem.

if object.discard
   # Psych::DisallowedClass:
   #   Tried to load unspecified class: ActiveSupport::TimeWithZone

I've tried each of the following config settings added to config/application.rb but the issue still persists(no spring running, no preloading)

# config.active_record.yaml_column_permitted_classes = [Symbol, Hash, Array, ActiveSupport::HashWithIndifferentAccess, ActiveSupport::TimeWithZone, Time]
# config.active_record.use_yaml_unsafe_load
# config.active_support.use_yaml_unsafe_load

Ruby version: 3.1.2 | Rails version: 6.1.7

Related question:

Upgrading to Ruby 3.1 causes Psych::DisallowedClass exception when using YAML.load_file

As a temporary workaround, I've rolled back to 6.1.6 Rails version but I'm looking for a proper solution to this issue.

2

There are 2 best solutions below

5
erwin On BEST ANSWER

Add the following to the file config/application.rb.

config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time, ActiveSupport::TimeWithZone, ActiveSupport::TimeZone]

It should solve the issue. Then restart the server and reload! the Rails console to ensure it works.

Credit to a comment above for providing this solution.

0
Jin Lim On

Also, ActiveSupport::HashWithIndifferentAccess, BigDecimal has issues. Please add. if you have any trouble.

config/application.rb

config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time, ActiveSupport::TimeWithZone, ActiveSupport::TimeZone, ActiveSupport::HashWithIndifferentAccess, BigDecimal]