Skip to content

Commit

Permalink
Eager autoload ActiveRecord::TableMetadata
Browse files Browse the repository at this point in the history
Fixes a bug that can occur when ActiveJob tries to access ActiveRecord.

Specifically, I had an Active Job process fail on Sidekiq with this error:

```
ActiveJob::DeserializationError: Error while trying to deserialize arguments:
uninitialized constant ActiveRecord::Core::ClassMethods::TableMetadata
Did you mean? ActiveRecord::TableMetadata
```

raised by these lines of code:

```
[GEM_ROOT]/gems/activerecord-5.0.0.1/lib/active_record/core.rb:300 :in `table_metadata`
298
299       def table_metadata # :nodoc:
300         TableMetadata.new(self, arel_table)
301       end
302     end
[GEM_ROOT]/gems/activerecord-5.0.0.1/lib/active_record/core.rb:273 :in `predicate_builder`
[GEM_ROOT]/gems/activerecord-5.0.0.1/lib/active_record/core.rb:290 :in `relation`
```

The problem seems to be that, inside ActiveRecord::Core, the `TableMetadata`
class has not been loaded and, therefore, Rails tries to access the constant
`ActiveRecord::Core::ClassMethods::TableMetadata` which does not exist.

Eager loading `ActiveRecord::TableMetadata` should fix the issue.

@rafaelfranca -- see our Campfire discussion
  • Loading branch information
claudiob committed Aug 15, 2016
1 parent c8d9a11 commit bb48866
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record.rb
Expand Up @@ -68,7 +68,6 @@ module ActiveRecord
autoload :StatementCache
autoload :Store
autoload :Suppressor
autoload :TableMetadata
autoload :Timestamp
autoload :Transactions
autoload :Translation
Expand Down Expand Up @@ -101,6 +100,7 @@ module ActiveRecord
end

autoload :Result
autoload :TableMetadata
end

module Coders
Expand Down

0 comments on commit bb48866

Please sign in to comment.