1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/lib
eileencodes bfec23aecb Fix PG::ConnectionBad error when running fixtures
At first this appeared to be a multi-db bug but after some invesitgation
it was clear that this can occur just by calling `establish_connection`
from ApplicationRecord.

After some investigation we found that this only occurred when using
fixtures. The console boots fine, the server runs fine, and the tests
even run fine if we used paralellization or eager loading in the tests.

I tracked the issue down to the line that calls
`self.connection_specification_name = name` in the SchemaMigration
changes for Rails 6.0. But how can this be? That is not that major of a
change? How could `connection_specification_name` be a problem?

First `connection_specification_name` caches the name of the connection
specificatio. Second, fixtures were incorrectly holding onto a reference
to that connection.

So when you went to run the tests the models wouldn't be connected and
when the fixtures tried to load the data it would choke on that
unconnected database.

The changes here move the connection into a lambda so we can call it
when we need it rather than blowing up before the model is connected.

Fixes #36743

Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
2019-08-02 15:22:11 -04:00
..
active_record Fix PG::ConnectionBad error when running fixtures 2019-08-02 15:22:11 -04:00
arel Address to rubocop offences 2019-07-31 17:48:14 +09:00
rails/generators Enable Layout/EmptyLinesAroundAccessModifier cop 2019-06-13 12:00:45 +09:00
active_record.rb Refactor Relation#cache_key is moved from CollectionCacheKey#collection_cache_key 2019-04-04 13:18:59 +09:00
arel.rb Remove unused Arel::Attributes.for 2019-06-15 23:59:41 +09:00