0

Upgrading a project from Rails 5.2, made it to 7.1.4 and it's producing an odd issue serializing jsonb. Given the lack of information I've found, this appears to be an unusual issue.

The error encountered

NoMethodError: NoMethodError
from /home/kevin/.rvm/gems/ruby-3.3.4/gems/activemodel-7.1.4/lib/active_model/type/value.rb:145:in `as_json'

Backtracking, the errant as_json is called on instances of ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb

This occurs on field where there is a Hash being serialized is in this shape:

{"name"=>"audited_changes",
 "value_before_type_cast"=>{:this=>[nil, "something"]},
 "type"=>#<ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb:... >,
 "original_attribute"=>
  #<ActiveModel::Attribute::FromDatabase:0x00007faf1e97bf60
   @name="audited_changes",
   @original_attribute=nil,
   @type=#<ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb:... >,
   @value_before_type_cast=nil>}

I've had this with both ActiveModel::Attribute::FromDatabase and ActiveModel::Attribute::FromUser

Any ideas what could cause this and how to resolve it?

Version info: Ruby 3.3.4 Rails 7.1.4 PG 1.5.7 Audited 5.7.0 (source of this particular error)

Audited::Audit.create(auditable: admin, user: admin, action: 'update', audited_changes: {this: [nil, 'something']}, comment: 'because', version: 1)

1 Answer 1

0

Found the problem, it was related to a gem which was monkey-patching active record, where it deviated from the standard serialization path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.