Skip to content
Branch: master
Commits on Nov 22, 2019
  1. Merge pull request #37669 from BelenRemedi/recyclable-cache-keys

    eugeneius committed Nov 22, 2019
    Update fragment caching doc [ci skip]
Commits on Sep 30, 2019
  1. Include connection in cached query notifications

    eugeneius committed Sep 30, 2019
    Since 6d1c9a9 the `sql.active_record`
    notification includes the connection that executed the query, but only
    when the result comes from the database, not the query cache.
  2. Always use 28 characters for Active Storage keys

    eugeneius committed Sep 30, 2019
    Active Storage keys are generated in two ways: in the `before_create`
    callback added by `has_secure_token`, or by calling `key` before the
    blob is saved. a273da7 broke the
    former code path, and the latter was previously untested.
Commits on Sep 17, 2019
  1. Allow ActionDispatch::Response to be autoloaded

    eugeneius and serenaf committed Sep 17, 2019
    Similar to b744372, this defers loading
    `ActionDispatch::Response` until after initialization, which will allow
    applications to boot a bit faster in development but also paves the way
    for `return_only_media_type_on_content_type` to work correctly when set
    from `new_framework_defaults_6_0.rb`.
        $ cat test.rb
        require "bundler/setup"
        before = ObjectSpace.each_object(Module).count
        start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
        require "action_controller"
        finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
        after = ObjectSpace.each_object(Module).count
        puts "took #{finish - start} and created #{after - before} modules"
        $ ruby test.rb
        took 0.35654300000169314 and created 608 modules
        $ ruby test.rb
        took 0.2770050000108313 and created 466 modules
    Co-authored-by: Serena Fritsch <>
  2. Merge pull request #37227 from john-denisov/patch-1

    eugeneius committed Sep 17, 2019
    Fix typo and simplify autoload paths intro
  3. Merge pull request #37221 from giraffate/fix_typo_in_actionmailbox_in…

    eugeneius committed Sep 17, 2019
    Fix typo in ActionMailbox::InboundEmail::MessageId [ci skip]
Commits on Sep 13, 2019
  1. Stop autoloading AbstractAdapter prematurely

    eugeneius committed Sep 12, 2019
    In 7254d23, an autoload for
    `ConnectionAdapters::AbstractAdapter` was added to `active_record.rb`.
    Later in d6b923a, a manual require for
    that class was added to `active_record/base.rb` as some constants under
    `ConnectionAdapters` weren't defined until `AbstractAdapter` was loaded.
    In 1efd882, the require was removed and
    replaced with an autoload in `active_record.rb`, above the previous one.
    Because the first autoload was for the `ConnectionAdapters` constant and
    the second one tried to create it, the autoload would fire immediately.
    Rather than fixing the autoload problem, the require had effectively
    just been moved from `active_record/base.rb` to `active_record.rb`.
    Instead of defining autoloads for constants under `ConnectionAdapters`
    in the `abstract_adapter.rb` file, we can create a separate, autoloaded
    `connection_adapters.rb` file for this purpose.
    To avoid a "circular require considered harmful" warning from Ruby, we
    have to fix the module nesting in `schema_creation.rb`, as a followup to
    `AbstractAdapter` loads many other dependencies, so making it autoload
    properly has a noticeable impact on the load time of `active_record.rb`.
        $ cat test.rb
        require "bundler/setup"
        before = ObjectSpace.each_object(Module).count
        start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
        require "active_record"
        finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
        after = ObjectSpace.each_object(Module).count
        puts "took #{finish - start} and created #{after - before} modules"
        $ ruby test.rb
        took 0.47532399999909103 and created 901 modules
        $ ruby test.rb
        took 0.3299509999342263 and created 608 modules
Commits on Sep 11, 2019
  1. Skip insert all tests when features are unavailable

    eugeneius committed Sep 11, 2019
    These tests are causing the Ruby master build to fail in CI. The Docker
    image we use is based on Ubuntu Bionic which provides SQLite 3.22.0, and
    the features required to use `insert_all` and `upsert_all` are not
    available in that version.
Commits on Sep 10, 2019
  1. Accept columns passed with options in remove_index

    eugeneius committed Sep 10, 2019
    Before this patch, column names could only be passed as a positional
    argument when no other options were supplied:
        remove_index :reports, :report_id
    Passing column names positionally along with other options would fail:
        remove_index :reports, :report_id, unique: true
        # => ArgumentError: wrong number of arguments (given 3, expected 1..2)
Commits on Sep 9, 2019
  1. Allow bulk alter to drop and recreate named index

    eugeneius committed Sep 9, 2019
    In 3809c80, adding an index with a
    name that's already in use was changed from an error to a warning, to
    allow other statements in the same migration to complete successfully.
    In 55d0d57 this decision was reversed,
    but instead of allowing the statement to execute and raise an adapter-
    specific error as it did before, an `ArgumentError` was raised instead.
    This interferes with a legitimate use case: on MySQL, it's possible to
    drop an index and add another one with the same name in a single `ALTER`
    statement. Right now an `ArgumentError` is raised when trying to do so,
    even though the resulting statement would execute successfully.
    There's no corresponding `ArgumentError` raised when attempting to add a
    duplicate column, so I think we can safely remove the check and allow
    the adapter to raise its own error about duplicate indexes again.
  2. Merge pull request #37125 from p8/fix-autosave-docs

    eugeneius committed Sep 9, 2019
    Improve autosave documentation [ci skip]
Commits on Sep 8, 2019
  1. Clear query cache when insert all is used

    eugeneius committed Sep 8, 2019
    The `InsertAll` class currently calls `exec_query`, which doesn't give
    the query cache enough information to know that it needs to be cleared.
    By adding an `exec_insert_all` method that calls `exec_query` internally
    we can configure the query cache to clear when that method is called.
Commits on Sep 7, 2019
  1. Allow inspected records to be marshaled

    eugeneius committed Sep 7, 2019
    Since 32b03b4, records which have had
    `inspect` called on them can't be marshaled, because of this anonymous
    `DelegateClass`. We can fix this by giving the class a concrete name.
Commits on Sep 4, 2019
  1. Merge pull request #37127 from Shopify/railtie-documentation

    eugeneius committed Sep 4, 2019
    Safer example in Rails::Railtie documentation
Commits on Sep 1, 2019
  1. Fix Active Job Sidekiq integration tests

    eugeneius committed Sep 1, 2019
    The `Sidekiq::Logging` module was removed in Sidekiq 6.0 in favour of
    > The old Sidekiq::Logging class was removed in Sidekiq 6.0. You should
    > not be accessing any Sidekiq internal classes to use the logger. Use
    > `logger` directly in your Worker or use `Sidekiq.logger` elsewhere.
Commits on Aug 28, 2019
  1. Update stale issue comment to mention 6-0-stable

    eugeneius committed Aug 28, 2019
    6-0-stable is the release series that currently receives bug fixes.
  2. Clarify severe security issues maintenance policy [ci skip]

    eugeneius committed Aug 28, 2019
    It wasn't clear whether "the last major release series" meant the most
    recent series in the last major version, or all series in that version.
Commits on Aug 27, 2019
  1. Merge pull request #37055 from akshaymohite/rails-engines-guides-fix

    eugeneius committed Aug 27, 2019
    Changed controller name (Typo fix) in rails engines documentation [ci skip]
  2. Merge pull request #37050 from quanon/fix_rdoc

    eugeneius committed Aug 27, 2019
    Fix rdoc of ActiveRecord::Associations::CollectionProxy#replace [ci skip]
Commits on Aug 26, 2019
  1. Always load validator class to verify it exists

    eugeneius committed Aug 26, 2019
    When updating our app for 9def053, I
    found several incorrectly configured validations that looked like this:
        validates :name, uniqueness: true, case_sensitive: false
    The intent is clearly for `case_sensitive: false` to be passed as an
    option to the uniqueness validator, but instead it's being passed as
    its own separate validation. Because the value `false` disables the
    validation, the validator class isn't loaded and the failure is silent.
    The validator should always be loaded, even if it's disabled, to ensure
    it exists and avoid configuration errors like the one described above.
  2. Merge pull request #28862 from georgemillo/show_detailed_exceptions

    eugeneius committed Aug 26, 2019
    fix docs for show_detailed_exceptions?
Commits on Aug 15, 2019
  1. Fix new default value for return_only_media_type_on_content_type

    eugeneius committed Aug 15, 2019
    Uncommenting this line should opt applications in to the new behaviour;
    in this case, `false` is the value needed to do that. This is the value
    set when `config.load_defaults 6.0` is called:
Commits on Aug 14, 2019
  1. Fix setting connection_specification_name on ActiveRecord::Base

    eugeneius committed Aug 14, 2019
    Since 2f8b397, `ActiveRecord::Base` and
    `ApplicationRecord` use the same default `connection_specification_name`
    so that database connections configured on `ApplicationRecord` also
    apply to `ActiveRecord::Base`.
    However, when resolving the connection for `ApplicationRecord` we should
    continue to fall back to `ActiveRecord::Base` when there's no connection
    explicitly configured, so that setting `connection_specification_name`
    on `ActiveRecord::Base` affects `ApplicationRecord` and its descendants
    in this case as it did in previous versions.
Commits on Aug 3, 2019
  1. Use media_type instead of content_type internally

    eugeneius committed Aug 3, 2019
    These calls to `content_type` were triggering the deprecation from
    c631e8d in upgraded applications.
    We can use `media_type` in all of these cases to avoid the deprecation.
Commits on May 18, 2019
  1. Return parameters enumerator from transform_keys/!

    eugeneius committed May 18, 2019
    Previously calling `ActionController::Parameters#transform_keys/!`
    without passing a block would return an enumerator for the underlying
    hash, which was inconsistent with the behaviour when a block was passed:
    "bar").transform_keys { |k| k }
        => <ActionController::Parameters {"foo"=>"bar"} permitted: false> "bar").transform_keys.each { |k| k }
        => {"foo"=>"bar"}
    An enumerator for the parameters is now returned instead, ensuring that
    evaluating it produces another parameters object instead of a hash:
    "bar").transform_keys.each { |k| k }
        => <ActionController::Parameters {"foo"=>"bar"} permitted: false>
Commits on May 12, 2019
  1. Remove SQLite version support caveats [ci skip]

    eugeneius committed May 12, 2019
    Since d1a74c1, Active Record requires
    SQLite version 3.8.0 or greater, so savepoints and partial indexes are
    always available.
    That commit also added a runtime version check, so we can remove the
    minimum version requirement from the internal adapter documentation.
Commits on Feb 20, 2019
  1. Add missing require to active_storage.rb

    eugeneius committed Feb 20, 2019
    Since b21f50d, requiring active_storage
    on its own has failed with the following error:
        activestorage/lib/active_storage.rb:55:in `<module:ActiveStorage>': undefined method `minutes' for 5:Integer (NoMethodError)
Commits on Nov 11, 2018
  1. Remove ensure from with_transaction_returning_status

    eugeneius committed Nov 11, 2018
    The test added in 12b0b26 passes even
    without this code since 9b8c779, as the
    call to `id` in `remember_transaction_record_state` now triggers a
    `sync_with_transaction_state` which discards the leftover state from the
    previous transaction.
    This issue had already been fixed for `save!`, `destroy` and `touch` in
    caae79a, but continued to affect `save`
    because the call to `rollback_active_record_state!` in that method would
    increment the transaction level before `add_to_transaction` could clear
    it, preventing the fix from working correctly.
    As `rollback_active_record_state!` was removed entirely in
    48007d5, this code is no longer needed.
Commits on Nov 7, 2018
  1. Always add records to parent of nested transaction

    eugeneius committed Nov 7, 2018
    When a record with transactional callbacks is saved, it's attached to
    the current transaction so that the callbacks can be run when the
    transaction is committed. Records can also be added manually with
    `add_transaction_record`, even if they have no transactional callbacks.
    When a nested transaction is committed, its records are transferred to
    the parent transaction, as transactional callbacks should only be run
    when the outermost transaction is committed (the "real" transaction).
    However, this currently only happens when the record has transactional
    callbacks, and not when added manually with `add_transaction_record`.
    If a record is added to a nested transaction, we should always attach it
    to the parent transaction when the nested transaction is committed,
    regardless of whether it has any transactional callbacks.
    [Eugene Kenny & Ryuta Kamizono]
Commits on Nov 6, 2018
  1. Fix inspect with non-primary key id attribute

    eugeneius committed Nov 6, 2018
    The `read_attribute` method always returns the primary key when asked to
    read the `id` attribute, even if the primary key isn't named `id`, and
    even if another attribute named `id` exists.
    For the `inspect`, `attribute_for_inspect` and `pretty_print` methods,
    this behaviour is undesirable, as they're used to examine the internal
    state of the record. By using `_read_attribute` instead, we'll get the
    real value of the `id` attribute.
Commits on Oct 21, 2018
  1. Reduce string allocations in read/write_attribute

    eugeneius committed Oct 21, 2018
    When `attr_name` is passed as a symbol, it's currently converted to a
    string by `attribute_alias?`, and potentially also `attribute_alias`,
    as well as by the `read_attribute`/`write_attribute` method itself.
    By converting `attr_name` to a string up front, the extra allocations
    related to attribute aliases can be avoided.
Commits on Oct 4, 2018
  1. Remove unreachable database warning

    eugeneius committed Oct 4, 2018
    `establish_connection` will never raise `ActiveRecord::NoDatabaseError`,
    because it doesn't connect to a database; it sets up a connection pool.
Commits on Sep 28, 2018
  1. Only define attribute methods from schema cache

    eugeneius committed Sep 26, 2018
    To define the attribute methods for a model, Active Record needs to know
    the schema of the underlying table, which is usually achieved by making
    a request to the database. This is undesirable behaviour while the app
    is booting, for two reasons: it makes the boot process dependent on the
    availability of the database, and it means every new process will make
    one query for each table, which can cause issues for large applications.
    However, if the application is using the schema cache dump feature, then
    the schema cache already contains the necessary information, and we can
    define the attribute methods without causing any extra database queries.
Commits on Sep 24, 2018
  1. Eagerly define attribute methods in production

    eugeneius committed Sep 24, 2018
    The attribute methods for a model are currently defined lazily the first
    time that model is instantiated, even when `config.eager_load` is true.
    This means the first request to use each model incurs the cost, which
    usually involves a database round trip to fetch the schema definition.
    By defining the attribute methods for all models while the application
    is booting, we move that work out of any individual request. When using
    a forking web server, this also reduces the number of times the schema
    definition is queried by doing it once in the parent process instead of
    from each forked process during their first request.
Commits on Aug 13, 2018
  1. Omit BEGIN/COMMIT statements for empty transactions

    eugeneius committed Aug 13, 2018
    If a transaction is opened and closed without any queries being run, we
    can safely omit the `BEGIN` and `COMMIT` statements, as they only exist
    to modify the connection's behaviour inside the transaction. This
    removes the overhead of those statements when saving a record with no
    changes, which makes workarounds like `save if changed?` unnecessary.
    This implementation buffers transactions inside the transaction manager
    and materializes them the next time the connection is used. For this to
    work, the adapter needs to guard all connection use with a call to
    `materialize_transactions`. Because of this, adapters must opt in to get
    this new behaviour by implementing `supports_lazy_transactions?`.
    If `raw_connection` is used to get a reference to the underlying
    database connection, the behaviour is disabled and transactions are
    opened eagerly, as we can't know how the connection will be used.
    However when the connection is checked back into the pool, we can assume
    that the application won't use the reference again and reenable lazy
    transactions. This prevents a single `raw_connection` call from
    disabling lazy transactions for the lifetime of the connection.
You can’t perform that action at this time.