Closed unrooty closed 6 years ago
Looks like Rails is grabbing the wrong constant - not in Representable's hand. Maybe dig into the yaml_column
code?
This is the code of yaml_column.rb 'load' method:
def load(yaml)
return object_class.new if object_class != Object && yaml.nil?
return yaml unless yaml.is_a?(String) && /^---/.match?(yaml)
obj = YAML.load(yaml)
assert_valid_value(obj, action: "load")
obj ||= object_class.new if object_class != Object
obj
end
I think it tries to create an instance of module and throws exception while this process. But I don't understand why it tries to create instance of JSON module in yaml_column.
Yepp, must be somewhere further up the stack. Is Rails maybe looking for constants that equal JSON
or something nasty like that? :thinking:
Could it be here: https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/blob.rb#L22 ? This is the first use of JSON
when going up the stack.
This is the culprit, replacing JSON
with ActiveRecord::Coders::JSON
fixes the issue. I will submit a PR to Rails.
@renchap thank for work. Waitng for megre.
It has been merged into the 5-2-stable
branch. You can switch rails
to this branch in your Gemfile to get the fix, or wait for the next Rails 5.2 version to be released.
I updated to Rails 5.2.0.rc1 and now have such error:
activerecord-5.2.0.rc1/lib/active_record/coders/yaml_column.rb:24:in 'load': undefined method 'new' for Representable::JSON:Module (NoMethodError)
Can anybody help me with this issue?