Skip to content
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

ActiveRecord::Base.using(...).connection.column_exists?(...) temporary breaks current shard #503

Open
rabotyaga opened this issue Sep 20, 2018 · 2 comments
Labels

Comments

@rabotyaga
Copy link

ar-octopus (0.9.1)
activerecord (4.2.7.1)
pg (0.18.4)

ActiveRecord::Base.using(...).connection.column_exists?(...) temporary breaks current shard, but after 1st request it is restored:

> Thread.current['octopus.current_shard']
 => :master 
> ActiveRecord::Base.using(:shard1).connection.column_exists?(:table, :column)
 => true 
> Thread.current['octopus.current_shard']
 => :shard1 
> ActiveRecord::Base.connection.execute('select 1')
[Shard: shard]   (0.4ms)  select 1
 => #<PG::Result:0x0000000009eb8850 status=PGRES_TUPLES_OK ntuples=1 nfields=1 cmd_tuples=1> 
> Thread.current['octopus.current_shard']
 => :master 

however Octopus.using(...) with a block does not:

> Octopus.using(:shard1) { puts ActiveRecord::Base.connection.column_exists?(:table, :column); puts Thread.current['octopus.current_shard'] }; puts Thread.current['octopus.current_shard']
true
shard1
master
 => nil 
@thiagopradi
Copy link
Owner

Hi @rabotyaga,

This seems like a bug - unfortunately, not an easy one to fix. I'll try to write a bugfix here for this bug - but, in the meanwhile, I would advise you, to stick with the using with block case.

Thiago

@rabotyaga
Copy link
Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants