audited: undefined class/module ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer during deserialisation

I’m in the middle of upgrading a decent sized application to Rails 5, and audited is one of the gems we love and enjoy to use a fair bit.

With one of the objects I am running into the following error when we call associated_audits on it:

undefined class/module ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer

I’ve checked and followed all guidance here in general about upgrades, and have been flailing about on this issue long enough to come here.

Here is my stacktrace:

ArgumentError: undefined class/module ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/class_loader.rb:53:in `path2class'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/class_loader.rb:53:in `resolve'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/class_loader.rb:45:in `find'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/class_loader.rb:27:in `load'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:379:in `resolve_class'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:207:in `visit_Psych_Nodes_Mapping'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:15:in `visit'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:5:in `accept'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:31:in `accept'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:321:in `block in revive_hash'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `each'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `each_slice'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `revive_hash'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:161:in `visit_Psych_Nodes_Mapping'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:15:in `visit'
    from /Users/my_user_name/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:5:in `accept'
... 62 levels...
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/attribute_set.rb:42:in `fetch_value'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods/read.rb:66:in `_read_attribute'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods/read.rb:53:in `read_attribute'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods.rb:297:in `attribute_for_inspect'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/core.rb:485:in `block in inspect'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/core.rb:483:in `collect'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/core.rb:483:in `inspect'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:683:in `map!'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:683:in `inspect'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/my_user_name/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
  from bin/rails:4:in `require'

The object runs a standard

audited
has_associated_audits

in the model file.

Would love to hear your feedback on what I’m missing here, also more than happy to provide any other supplementary info as needed. I’ll have the window open for the next ten hours or so and should be quick to respond today and tomorrow.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 3
  • Comments: 19 (3 by maintainers)

Most upvoted comments

This may be related, I ran into the same issue when upgrading from Rails 4.2 to Rails 5. I solved the NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer error by clearing the Rails cache on the production site.

Rails.cache.clear

So im facing the same exception upgrading my app and i think see whats the problem…

I have this at audited_changes column:

---
aluno_presenca:
- !ruby/object:AlunoPresenca::AConfirmar
  owner: !ruby/object:Aula
    raw_attributes:
      conta_id: 2408
      aluno_id: '28697'
      aluno_presenca: presente
    attributes: !ruby/object:ActiveRecord::AttributeSet
      attributes: !ruby/object:ActiveRecord::LazyAttributeHash
        types:
          id: &1 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer
            precision:
            scale:
            limit:
            range: !ruby/range
              begin: -2147483648
              end: 2147483648
              excl: true
          conta_id: *1
          aluno_id: *1
...

And ActiveRecord 5.0 does not include ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer anymore… The parse tries to instantiate this object and BOOM.

Not sure why the entire object is serialized this way… You guys see a solution here besides deleting these audits?