-
Notifications
You must be signed in to change notification settings - Fork 87
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
Validations create empty translations in DB #569
Comments
Please write a failing test, that's much clearer than a long explanation. |
See this failing spec: https://github.com/mrbrdo/mobility/blob/mrbrdo/spec/mobility/backends/active_record/table_spec.rb#L112 Also, I'm not sure that a fallback for |
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
Unfortunately the fix in #572 doesn't work with caching (several tests are failing on that branch). |
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
… prevent valid? on parent model (issue shioyama#569)
This is still a serious problem. I'd be willing to deal with cache misses if this would stop happening. Not only does it mess with validations (meaning I can't save records at all if I have a validation on the translation), it also caused a really difficult-to-pin-down bug when an Long story short - I need this pretty badly :) I'll take a look at #572 to see if I can get a better version working. @shioyama do you have any thoughts / suggestions for this? The case is really just "don't build a translation on read if it doesn't exist yet", which should be something we can patch for the table backend. It shouldn't affect cache because the value by definition will always be nil in this case - there's nothing to cache. |
I am using fallbacks. One of my locales is "en-GB", and I think the I18n fallbacks defaults to "en" as a fallback.
However this bug exists also without fallbacks, it's just easier to explain this kind of case.
During validations, translation_for will be called:
https://github.com/shioyama/mobility/blob/master/lib/mobility/backends/active_record/table.rb#L291
It will build a translation for this "en" locale, even though this is not necessary.
Additionally I have a presence validation on the Translation class (friendly_id slug). Therefore due to this, I cannot save my models, because fallbacks is generating empty translations on the model. Even if I did not have that validation, it would create unwanted empty translations in the DB upon saving.
Temporarily I fixed it by patching generate_fallbacks to exclude the 'en' locale, but that only partly fixes it - only for models which have translations for all locales I use.
Possible solution would be for the reader to not call build, and only writer to call build. I can whiff up a PR if you think that solution is the best we can do.
The text was updated successfully, but these errors were encountered: