Reputation: 441
I'm trying to run Rails 5 and Rails 6 simultaneously and have encountered a caching issue when the Rails 5 & 6 versions of the project share the same external cache. After the Rails
5 version of the project caches an ActiveRecord object, when the Rails 6 version reads from the cache and tries to read cached_object.id
, it returns nil
. Interestingly enough, cached_object[:id]
returns the correct value.
Our caching implementation uses Marshal under the hood to serialize/deserialize, so I was able to reproduce this without the cache dependency, as follows:
Given a project running Rails 5:
usr = User.find_by_id(1)
puts Marshal.dump(usr)
Copy and paste the result of Marshal.dump
to another console running Rails 6:
usr = Marshal.load(<COPY_PASTE_STRING>)
usr.id // returns nil
usr[:id] // returns 1
The opposite doesn't seem to be true (ie. Marshal.dump
in Rails 6 and Marshal.load
in Rails 5 doesn't reproduce this)
Is anybody familiar with the Rails internals that might know what's going on here?
Upvotes: 4
Views: 681
Reputation: 441
It turns out this behavior isn't an issue with Marshal, but rather a change in ActiveRecord in Rails 6.
Upvotes: 2