-
Notifications
You must be signed in to change notification settings - Fork 167
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
Tenant.switch! raises exception on first call / Postgresql #92
Comments
This happens when Probably, replacing |
@psunix in which moment are you calling I'm still trying to find out what's the best info you can provide for me to simulate your use case, so for now, if you can reproduce the error in a sample app that would be awesome. |
@rpbaltazar thx for your help. we're calling switch inside our gem for checking if all migrations have completed: https://github.com/puzzle/bleib/blob/master/lib/bleib/migrations.rb#L62 I think it's a special situation here. @codez was able fixing it be first calling Apartment::Tenant.reload! in the rake task we use to check if all migrations have completed. |
In that gem, we actually call Because of apartment/lib/apartment/railtie.rb Line 38 in 49ab159
Thread.current . Calling reload! would nilify Thread.current , so the correct adapter would be chosen on the subsequent initialization.
|
Wow, that was fast. Thank you very much for the fix! |
Steps to reproduce
In rails production env: Apartment::Tenant.switch!('public')
Expected behavior
it changes current tenant to public.
Actual behavior
raises an exception when trying to switch to any tenant.
System configuration
Database: Postgresql 9.5.14
pg gem: 1.2.3
OS: Linux / Docker
Apartment version: 2.7.1
Apartment config (in
config/initializers/apartment.rb
or so):Rails (or ActiveRecord) version: 6.0.3.2
Ruby version: 2.5.5
The text was updated successfully, but these errors were encountered: