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

Locale from session can be a symbol, but causes sidekiq web to error out #6271

Closed
mishaelajay opened this issue Apr 29, 2024 · 0 comments
Closed

Comments

@mishaelajay
Copy link
Contributor

mishaelajay commented Apr 29, 2024

Ruby version: 3.2.4
Rails version: 7.1.3
Sidekiq / Pro / Enterprise version(s): 7.2.4

Please include your initializer, sidekiq.yml, and any error message with the full backtrace.

I have a middleware setup on my application which will set the I18n.locale based on either the URL parameter
'locale', or if not available, use the first of the HTTP_ACCEPT_LANGUAGE
values to infer the locale to be used. It sets said locale as a symbol.

Sidekiq web throws the following error now on opening: TypeError: no implicit conversion of nil into Hash

On digging further this was thrown from here:

global.merge!(strs[lang])

@strings[lang] ||= settings.locales.each_with_object({}) do |path, global|
    find_locale_files(lang).each do |file|
    strs = YAML.safe_load(File.read(file))
    global.merge!(strs[lang])
end

Since this was working until Sidekiq 7.2.2 i figured this must be due to a recent change which led me to:
https://github.com/sidekiq/sidekiq/pull/6217/files#diff-a19b19d20df90597eaac2e2edc433b5d56d1d30a8501029bfd9688a8980dd150R124-R127

# session[:locale] is set via the locale selector from the footer
# defined?(session) && session are used to avoid exceptions when running tests
return session[:locale] if defined?(session) && session&.[](:locale)

Prior to this change, when the :locale is not set within the session it defaults to "en"
Post this change, it uses the session['locale'] if available which in my application is always a symbol.
But since the strings method has strs which loads the locales as a hash with strings as keys it will cause the above mentioned error.

I have a possible fix for this in this PR: #6272

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

1 participant