S. Chekan
S. Chekan

Reputation: 11

Rails 7.1 Error when reading active record model from redis cache

We have a problem during upgrade Rails from 7.0.8 to 7.1.3.2 with reading AR models from Redis cache.

We have several places where we cache AR models with Redis:

Rails.cache.fetch("key_name") { Ar_Model[some_key] }

After Rails upgrade we can't read all params (except id) from model. Example:

Run two same consoles. In one of them:

model = Rails.cache.fetch("key_name") { Ar_Model[some_key] }
model.class => Ar_Model(id: integer, name: string)
model.name => "some_name"

But in the second console:

model = Rails.cache.fetch("key_name")
model.class => Ar_Model(id: integer, name: string)
model.id => some_id
model.name => Error! Unknown method 'name' for Ar_Model()

Interestingly, after run, for example, Ar_Model.first in the second console, we can read all params from model without any reloading.

model = Rails.cache.fetch("key_name")
model.class => Ar_Model(id: integer, name: string)
model.id => some_id
model.name => Error! Unknown method 'name' for Ar_Model()
Ar_Model.first
model.name => "some_name"

Upvotes: 1

Views: 61

Answers (0)

Related Questions