-
Notifications
You must be signed in to change notification settings - Fork 24
Raise when calling connection on a sharded model without a shard #131
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
base: main
Are you sure you want to change the base?
Conversation
0ca6ae7 to
0e16bc7
Compare
test/connection_switching_test.rb
Outdated
|
|
||
| if ActiveRecord::VERSION::MAJOR > 3 | ||
| describe "ActiveRecord::Base.connection.schema_cache.columns_hash" do | ||
| before do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a bit more indentation from here and down.
0e16bc7 to
5de0c78
Compare
| nil | ||
| else | ||
| @shard || self.class.default_shard | ||
| @shard || self.class.default_shard || raise('You can not connect a sharded model without calling on_shard.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe next PR should be removing default_shard ;)
| end | ||
| end | ||
|
|
||
| it 'explodes when a shard has been specified for sharded model' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it 'works ...
|
How does this play with #130? |
|
@jacobat I would assume your PR would be fine. Our issue in Classic is some code paths relying on |
/cc @bquorning @grosser @kassio @craig-day
When calling
Model.connectionon a sharded model when we're not on a shard returns a connection to the unsharded database. This PR fixes the issue by raising when trying to callconnectionwithout specifying a shard.fyi @jacobat