Skip to content

Conversation

@hila-f-qodo
Copy link

The FallbackLocaleList object tells I18n::Backend::Fallbacks what order the
languages should be attempted in. Because of the translate_accelerator patch,
the SiteSetting.default_locale is *not* guaranteed to be fully loaded after the
server starts, so a call to ensure_loaded! is added after the locale is set for
the current user.

The declarations of config.i18n.fallbacks = true in the environment files were
actually garbage, because the I18n.default_locale was
SiteSetting.default_locale, so there was nothing to fall back to. *derp*
@qodo-code-review
Copy link

qodo-code-review bot commented Dec 23, 2025

Code Review by Qodo (Alpha)

Grey Divider

Analysis Completed

Published 2 inline comment(s)

Grey Divider

Qodo Logo

Comment on lines +62 to +65
def ensure_loaded!(locale)
@loaded_locales ||= []
load_locale locale unless @loaded_locales.include?(locale)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[remediation_recommended] [Thread-safety concern in ensure_loaded!]
• The new ensure_loaded! method uses @loaded_locales ||= [] outside of any mutex synchronization
• Multiple threads could race on this initialization, each creating separate arrays
• While load_locale has internal mutex protection preventing duplicate loading, the unsynchronized access is a code smell
• The pattern is inconsistent with how load_locale handles @loaded_locales access (inside LOAD_MUTEX)

Agent Prompt
Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## Issue description
The ensure_loaded! method accesses @loaded_locales outside of mutex synchronization, creating a race condition window and pattern inconsistency with load_locale.

## Issue Context
load_locale already has internal synchronization via LOAD_MUTEX and checks if the locale is already loaded. The external check in ensure_loaded! is redundant and introduces thread-safety concerns.

## Fix Focus Areas
- lib/freedom_patches/translate_accelerator.rb[62-65]

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

Successfully merging this pull request may close these issues.

3 participants