shioyama/mobility

Cache issue with JSONb (+locale_accessors) & ActiveRecord

KevinSchiffmann opened this issue · 2 comments

Hello,

First of all, thank you very much for your work!

To summarize, we are using Mobility in a Rails 7.0.4 project, with jsonb backend and locale_accessors. We are actually using the master branch to fix the JSON dirty tracking issue with ActiveRecord.

The problem comes with "cache" enabled in Mobility configuration. Values of local_accessors are not immediatly visible in Rails model and validation fail.

Expected Behavior

Value assigned should be immediately visible in model (needed for validation, for example).

Actual Behavior

Value assigned is not immediatly reflected in model, which cause validation issues. For example, a simple model with a "translates" description attributes, and a presence validator:

irb(main):001:0> my_object = MyModel.find(1)
irb(main):002:0> my_object.description_en = nil
=> nil
irb(main):003:0> my_object.save # Should be false, because we deleted all translations
=> true
irb(main):004:0> my_object.save # After a second "save", the model see the right value and return false
=> false

Possible Fix

It's not a fix, but if you disable "cache" in mobility configuration, there no problem anymore and the validations works fine.

Thank you very much for your help!

Can you provide a failing spec? If not I can't help and will have to close this.

I can't reproduce it, I must be crazy... sorry for that!