Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 290
Nikita Fedyashev Avatar asked Sep 13 '25 10:09

Nikita Fedyashev


2 Answers

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.

like image 109
erwin Avatar answered Sep 14 '25 23:09

erwin


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]
like image 29
Jin Lim Avatar answered Sep 14 '25 23:09

Jin Lim