Skip to content
  • eileencodes's avatar
    d2761cfd
    Raise an error if `pool_config` is `nil` in `set_pool_config` · d2761cfd
    eileencodes authored
    In #41549 a user was getting an error that the `pool_config` was `nil`
    so the `all_connection_pools` method would raise an error. After getting
    a reproduction application I saw that if the application is
    misconfigured this can happen. For example, if an application uses
    `:all` for the writing role but does not set
    `config.active_record.writing_role = :all` then the
    `setup_shared_connection_pool` pool method will get a `nil` value for
    the `writing_pool_config` and set that in `set_pool_config`. I
    considered fixing this in `setup_shared_connection_pool` directly and
    raising an error there, but there's a possibility this _can_ happen in
    an external gem or application code if they're using these private APIs
    and realistically we never want any code, Rails or otherwise, to be able
    to set a `nil` pool config in the pools.
    
    Note: In the test I made a new connection handler so that we have
    isolated pools to test against. Otherwise we'll be testing against the
    existing pools but we don't want to mess those up.
    
    Closes #41549
    d2761cfd
    Raise an error if `pool_config` is `nil` in `set_pool_config`
    eileencodes authored
    In #41549 a user was getting an error that the `pool_config` was `nil`
    so the `all_connection_pools` method would raise an error. After getting
    a reproduction application I saw that if the application is
    misconfigured this can happen. For example, if an application uses
    `:all` for the writing role but does not set
    `config.active_record.writing_role = :all` then the
    `setup_shared_connection_pool` pool method will get a `nil` value for
    the `writing_pool_config` and set that in `set_pool_config`. I
    considered fixing this in `setup_shared_connection_pool` directly and
    raising an error there, but there's a possibility this _can_ happen in
    an external gem or application code if they're using these private APIs
    and realistically we never want any code, Rails or otherwise, to be able
    to set a `nil` pool config in the pools.
    
    Note: In the test I made a new connection handler so that we have
    isolated pools to test against. Otherwise we'll be testing against the
    existing pools but we don't want to mess those up.
    
    Closes #41549
Loading