-
Notifications
You must be signed in to change notification settings - Fork 335
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
Unexpected interaction with I18n #452
Comments
Can't reproduce an issue. So would you provide a test app? |
I can't make it happen in a toy app, but I did bisect the changes between 6.1.0 and 6.2.0, and the change that's causing our I18n to be modified is in #431. I'm looking now to see if I can tell why, it's not apparent at all why this would happen. |
If I comment out this entire block, the mutation doesn't happen, but it has to be everything in this block including the initializer itself:
|
Is there something about this initializer technique that might be mutating the middleware stack or nullifying other changes made to the stack? The mere use of |
I've seen something like this with the react-rails gem but I've not had the opportunity to debug it fully: reactjs/react-rails#1033 It looks like Rails itself encountered a related issue:
I'm guessing a similar issue is happening here. It might be worth trying variations on when the initializer runs: -initializer 'rack.attack.middleware', after: :load_config_initializers, before: :build_middleware_stack do |app|
+# No after, before options
+initializer 'rack.attack.middleware' do |app|
+# Try omitting and changing after and/or before options, values
+# listed at https://guides.rubyonrails.org/configuring.html#initializers
+initializer 'rack.attack.middleware', before: :build_middleware_stack do |app| |
Interesting. Have you checked what's the output of |
@grzuy it's the exact same order and contents for both. I suspect causing initializers to fire early is somehow to blame, but I haven't managed to put enough from our large application into a toy to replicate the same behavior. |
We were able to get around this issue in our application by removing a reference to Given that using rack-attack already requires configuration beyond just enabling the middleware, I'm not sure the convenience benefit of automatic inclusion offsets the risk of altering the order in which code is loaded in applications and the use of a private method to get the middleware loaded. I apologize for not yet being able yet to produce a small public repo to reproduce the problem. |
Weird... |
@geoffharcourt Also trying to troubleshoot this on my end. In the meantime, do you mind trying on your app if moving Thank you! |
Will do. One thing that might also be possible to try would be to do I still think this practice of using the before middleware initializer to autoload the middleware conditionally might be dangerous and cause unintended behaviors beyond the one I encountered. |
FWIW I was able to, at least, reproduce how |
…ems load order Because of the sort algorithm rails uses to satisfy `after` and `before` constraints, gems can have unintended effects on others. See rails/rails@0a120a8 Prefer making rack-attack middleware idempotent instead of relying on the load order and the contents of the middleware stack too much. closes #452 closes #456
Agree. |
Fixed in |
I'm trying to generate a small test case app to demonstrate this issue, but we experienced something odd when we tried to upgrade our Rails 6.0.0 app from rack-attack 6.1.0 to 6.2.0. The PR with the update, which does nothing beyond bump the one line in Gemfile.lock for rack-attack, results in all of our explicitly defined
time.formats
in our I18n locale files being replaced with the out-of-the-box formats distributed by Rails. We use YAML files inconfig/locales/*.yml
to set our formats, and when I inspect them withI18n.backend.translations[:en][:time]
, I can see that with rack-attack 6.2.0 they are no longer what they normally are in our app.I'm completely unclear how this could happen, as I can't find references to I18n or
formats
in the gem, but flipping the gem version back and forth in our development and test environments causes the formats in ourconfig/locales/en.yml
file to be wiped out.The text was updated successfully, but these errors were encountered: