I have a rails initializer that sets the limit on Big Decimal
BigDecimal.limit(20)
This is executed and seems to set the limit properly.
But when a web request comes in (I am using Puma), the limit does not appear to be set on the thread that handles the request. The limit is set to 0 which is the default.
Is there somewhere else I should be setting the limit?
If you want to reproduce:
create a brand new rails app and add an initializer that sets limit
BigDecimal.limit(20)
puts "*** Set #{BigDecimal.limit}"
in your application controller add
before_action :check_big_decimal
def check_big_decimal
puts "***request #{BigDecimal.limit}"
end
start your server, refresh page and make a request
You should see it set to 20 but then it is back to 0 when the request comes in.
I got an answer from the Rails community
Basic gist is:
This happens because Ruby stores the BigDecimal limit in thread local storage. When e.g. Puma starts a new thread to handle a request, the new thread can't access the BigDecimal limit set in the initial thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With