4 ms·
Good to know: the lazy block is executed in a fiber, and fibers don’t share Thread.current. It took me hours to debug why Rails I18n.locale was not honored ins
by andruby 7y ago
Good to know: the lazy block is executed in a fiber, and fibers don’t share Thread.current.
It took me hours to debug why Rails I18n.locale was not honored inside the block.
- why-el 7y agoCan you elaborate? What were you doing to the locale? Changing it?
- nurettin 7y agoPerhaps gp means that the i18n data was initialized as thread-local, so it was missing in other threads.
- andruby 7y agoRails uses I18n.locale as a "global variable" to store the locale of the request. Behind the scenes this is stored in Thread.current[]. So if you have a request that sets the locale to non-default one and you perform some work inside a lazy block, I18n.locale will return an incorrect value inside that block.