-
Notifications
You must be signed in to change notification settings - Fork 1
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
Don't try and grab a connection after it (may) is established. #7
base: master
Are you sure you want to change the base?
Conversation
…s so that you can override the datasource (e.g. mock) and not get an error.
Waiting an hour for any objections. Otherwise looks good to me. |
Question: is calling So, for example, you might have: class UserModel < Peacekeeper::Model; end
class RestaurantModel < Peacekeeper::Model; end
Peacekeeper::Model.config = generic_config
Peacekeeper::Model.data_source = :active_record
# ^^^ At this point, both UserModel and RestaurantModel are connected to the DB specified in generic_config
RestaurantModel.config = restaurant_db_config
RestaurantModel.data_source = :active_record
# ^^^ The intention was to load Restaurants from a specific DB, but now both User and Restaurant are pointed at restaurant_db_config If you read the docs on |
If you want models to be able to connect to other things they can be set on their own with |
Removing the connection code doesn't fix the problem. Trying to get the connection right after establishing it just allowed the problem to come to a head more quickly. @jballanc, we can check for a data_class first and, if it isn't nil, then establish the connection. If it isn't nil, we can set it on the data_class. But I don't think that fixes the root of the problem. The root of the problem, as I see it, is that setting the the data_source tries to make a connection to the DB and it's assuming that connection is lazy. It won't actually try to connect until there is a DB query. AR is greedy and tries to establish a connection immediately. I don't know a ton about sequel so correct me if I'm wrong, @jballanc. It might be best to clearly state whether or not data_source should be lazy or greedy. I'd vote for lazy, but that means more work getting AR working. |
Ok, so obviously a little more digging into AR is in order. I agree that data connection should be as lazy as possible. It is not completely inconceivable that in a dev environment or testing (as in the case where you discovered this issue), the I would not be surprised if AR is making a query as part of Another possibility is that we could look at the guts of |
This is so that you can override the datasource (e.g. mock) and not get an error.