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 66bc2ff6b3 Call while_preventing_writes from connected_to
If a user is using the middleware for swapping database connections and
manually calling `connected_to` in a controller/model/etc without
calling `while_preventing_writes(false)` there is potential for a race
condition where writes will be blocked.

While the user could _just_ call `while_preventing_writes` in the same
place they call `connected_to` this would mean that all cases need to
call two methods.

This PR changes `connected_to` to call `while_preventing_writes`
directly. By default we'll assume you don't want to prevent writes, but
if called with `connected_to(role: :writing, prevent_writes: true)` or
from the middleware (which calls `connected_to` this way) the writes
will be blocked.

For replicas, apps should use readonly users to enforce not writing
rather than `while_preventing_writes` directly.

Should fix the remaining issues in
https://github.com/rails/rails/issues/36830
2019-08-28 13:44:51 -04:00
..
active_record Call while_preventing_writes from connected_to 2019-08-28 13:44:51 -04:00
arel Fix docs to replace http with https in activerecord [ci skip] 2019-08-26 22:34:33 +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