Breaking: Make request_store an optional dependency#296
Breaking: Make request_store an optional dependency#296willnet merged 3 commits intogazay:masterfrom
Conversation
BREAKING CHANGE: request_store is no longer a required dependency. For Rails < 5.2, users must explicitly add `gem 'request_store'` to their Gemfile. Rails 5.2+ users will automatically use ActiveSupport::CurrentAttributes instead. This modernizes the gem while maintaining support for older Rails versions.
willnet
left a comment
There was a problem hiding this comment.
The basic policy looks good (LGTM). Additionally, it would be better to have a test for when a LoadError occurs. I would like to add a test environment running a version below Rails 5.2 without request_store in the Gemfile to verify that the error message is displayed correctly.
Co-authored-by: Shinichi Maeshima <netwillnet@gmail.com>
8bbe714 to
7017390
Compare
|
@krororo It is true that the tests are passing even for Rails versions below 5.2 without request_store. However, what I was thinking of was creating a new job in .github/workflows/ci.yml, separate from the test job, to run gon in an environment with specific versions like Ruby 2.4 and Rails 5.1. Could you please make this adjustment? |
7017390 to
9e36954
Compare
Add a dedicated CI job to verify that gon properly raises an error with the expected message when used with Rails 5.1 without the request_store gem installed.
9e36954 to
9c13f62
Compare
|
@willnet Sorry for the delayed reply. |
|
v7.0.0 released! |
Summary
Remove hard dependency on request_store.
Problem
The gem currently depends on
request_store, which usesThread#[]for storage. However,Thread#[]provides fiber-local variables rather than thread-local variables, which can cause unexpected behavior in fiber-based concurrency scenarios.From Ruby documentation:
See: https://docs.ruby-lang.org/en/4.0/Thread.html#method-i-5B-5D
Solution
Rails 5.2 introduced
ActiveSupport::CurrentAttributes, which properly handles both thread and fiber contexts. This PR:CurrentAttributesfor Rails 5.2+ (no external dependency needed)RequestStorefor older Rails versions when availablerequest_storean optional dependency instead of requiredBreaking Change⚠️
IMPORTANT for Rails < 5.2 users:
If you're using Rails version earlier than 5.2, you must explicitly add
request_storeto your Gemfile:Rails 5.2+ users don't need any changes.