Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validates presence: true failing with cache active #623

Open
alejanderl opened this issue Jun 28, 2023 · 3 comments
Open

validates presence: true failing with cache active #623

alejanderl opened this issue Jun 28, 2023 · 3 comments

Comments

@alejanderl
Copy link

Hey, thanks for the library and great work.

We are implementing multi language with Mobility and we found this issue:

Context

We are using Mobility with a Rails 7 application and the v1.3.0.rc1

Expected Behavior

Deactivating the cache is making everything to work as expected

class SomeClass < ApplicationRecord
      translates :name, backend: :jsonb
      
      validates :name, presence: true
end

my_record = SomeClass.find(1)
#<SomeClass name: "Legolas" ... >  

my_record.update(name: "")
# false

my_record.valid?
# false

my_record.update(name: "Aragorn")
# true

Actual Behavior

With the cache active in the Mobility config we experienced this behaviour;

class SomeClass < ApplicationRecord
      translates :name, backend: :jsonb
      
      validates :name, presence: true
end

my_record = SomeClass.find(1)
#<SomeClass name: "Legolas" ... >  

my_record.update(name: "")
# true

my_record.valid?
# false

my_record.update(name: "Aragorn")
# false
@tot-ioki
Copy link

tot-ioki commented Nov 2, 2023

We're also experiencing this issue when using Rails 7 in conjunction with mobility 1.3.0.rc1.

@alejanderl did you find a way to work around this without having to disable the caching?

@shioyama
Copy link
Owner

Hi folks. I really need a failng test for this.

@doits
Copy link
Contributor

doits commented Mar 26, 2024

(Not a solution, but just want to give the hint that – if I am not mistaken – validates :name, presence: true will validate depending on the current ::I18n.locale which might be different for different requests (and will take into account plugins like fallback etc). Maybe this is what you want, but it could happen that a record is valid with ::I18n.locale = :en but invalid with ::I18n.locale = :de, just to keep that in mind.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants