Commit Graph

87383 Commits

Author SHA1 Message Date
Guillermo Iguaran
e99aa34f53
Merge pull request #47885 from zzak/rack-3-rackup-server
Fix Rack::Deprecation warning which causes this test to fail
2023-04-08 20:49:11 -07:00
Jonathan Hefner
7c208c7353
Merge pull request #47866 from ghiculescu/input-time-hh-mm
Allow a `value` formatted as `HH:MM` for `time_field`
2023-04-08 20:56:41 -05:00
zzak
97f0c3c4ef
Merge pull request #47850 from notapatch/api-docs-activerecord-validate-multiple-contexts
Add docs for Active Record validation with multiple contexts
2023-04-09 08:45:44 +09:00
zzak
a40e934f06
Merge pull request #47896 from zzak/re-47723
Fix WARNING block in security guide
2023-04-09 08:45:03 +09:00
zzak
24eeed9ef2
Fix WARNING block in security guide 2023-04-09 08:24:33 +09:00
Alex Ghiculescu
2d89108e40 Allow a value formatted as HH:MM for time_field
https://github.com/rails/rails/pull/46678 introduced a regression, if you do the following:

```ruby
= time_field(model, attr, value: "01:45")
```

Previously it would render an input with `value="01:45"`, since https://github.com/rails/rails/pull/46678 it renders a value with seconds (`value="01:45:00.000"`). This is a regression from Rails 7. See https://github.com/rails/rails/pull/41728 for why you might want the value to be rendered without seconds.

Co-authored-by: jonathanhefner <jonathan@hefner.pro>
2023-04-08 16:25:25 -06:00
zzak
05e946410b
Introduce Rails::Rackup::Server which is used by the bin/rails server command.
```
Failure:
Rails::Command::HelpIntegrationTest#test_prints_help_via_`X:help`_command_when_running_`X`_and_`X:X`_command_is_not_defined [/Users/zzak/code/rails/railties/t
est/command/help_integration_test.rb:33]:
--- expected
+++ actual
@@ -1,4 +1,5 @@
-"Commands:
+"Rack::Server is deprecated and replaced by Rackup::Server
+Commands:
   bin/rails dev:cache           # Toggle development mode caching on/off
   bin/rails dev:help [COMMAND]  # Describe available commands or one specific...
```

From @ioquatix:

> Yeah you need to load `rackup/server` and if you get `LoadError` fall back to `Rack::Server`.

This PR implements that paraphrasing, and resolves this deprecation:

```
Rack::Server is deprecated and replaced by Rackup::Server
```

Example build:
https://buildkite.com/rails/rails/builds/95468#0187559d-3190-4e6f-8ac5-65042b2a5412/1334-1342

Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
2023-04-09 07:14:41 +09:00
Aaron Patterson
2815cb9620
Merge pull request #47864 from zenspider/zenspider/ar_core_hash
Fix AR#== and AR#hash when new_record?
2023-04-08 14:48:29 -07:00
Ryan Davis
332caee459 Try fixing model equality tests by saving a record first.
These tests were invalid per the equality doco for new records. Saving
one of the records _should_ allow it to travel the old path.
2023-04-08 14:01:47 -07:00
Nikita Vasilevsky
8915da978b Flip eql? assertion for CPK new records 2023-04-08 13:33:45 -07:00
Aaron Patterson
7e4d374f76 Fix case when LHS is old record but RHS is new 2023-04-08 13:33:45 -07:00
Aaron Patterson
cd84c0ad3a Add a test for eql? on new objects
New objects shouldn't eql? other new objects even if the id column sets
the value to a default value
2023-04-08 13:33:45 -07:00
Ryan Davis
d4911c1ca3 Fix AR#== and AR#hash when new_record?
* Don't compute AR#== if new_record?
* Don't compute AR#hash if new_record?
* Use [array].hash for computing hash

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-04-08 13:33:45 -07:00
Jonathan Hefner
11a5e37715
Merge pull request #47890 from alexcwatt/finddbconfig-perf
ActiveRecord: Improve `find_db_config` performance
2023-04-08 12:24:12 -05:00
Alex Watt
d0570697f4 ActiveRecord: Improve find_db_config performance
I noticed an application spending ~5ms on `find_db_config`, with a lot
of time spent on sorting the database configs and comparing the arrays
(`Array#<=>`). I updated `find_db_config` to avoid the sort entirely.

Here is a benchmark script I used to measure the improvement:

```

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails", branch: "main"
  gem "benchmark-ips"
end

require "active_record"
require "active_record/database_configurations"

module ActiveRecord
  class DatabaseConfigurations
    def fast_find_db_config(env)
      current_env_configs, other_configs = configurations.partition(&:for_current_env?)
      [*current_env_configs, *other_configs].find do |db_config|
        db_config.env_name == env.to_s ||
          (db_config.for_current_env? && db_config.name == env.to_s)
      end
    end
  end
end

def generate_configs(adapter, count)
  count.times.to_h do |i|
    [i == 0 ? "primary" : "config_#{i}", { "adapter" => adapter }]
  end
end

small_config = ActiveRecord::DatabaseConfigurations.new(
  **generate_configs("sqlite3", 3)
)

large_config = ActiveRecord::DatabaseConfigurations.new({
  **generate_configs("randomadapter", 100),
  ActiveRecord::ConnectionHandling::DEFAULT_ENV.call => generate_configs("sqlite3", 100)
})

SCENARIOS = {
  "Empty"                   => ActiveRecord::DatabaseConfigurations.new({}),
  "A few connections"       => small_config,
  "Hundreds of connections" => large_config,
}

SCENARIOS.each_pair do |name, value|
  puts
  puts " #{name} ".center(80, "=")
  puts

  Benchmark.ips do |x|
    x.report("find_db_config") { value.find_db_config("primary") }
    x.report("fast_find_db_config") { value.fast_find_db_config("primary") }
    x.compare!
  end
end
```

The results show a consistent speedup, especially for many configs:

==================================== Empty =====================================

Warming up --------------------------------------
      find_db_config    82.849k i/100ms
 fast_find_db_config   172.141k i/100ms
Calculating -------------------------------------
      find_db_config    830.202k (± 1.9%) i/s -      4.225M in   5.091388s
 fast_find_db_config      1.633M (± 6.6%) i/s -      8.263M in   5.082794s

Comparison:
 fast_find_db_config:  1633426.8 i/s
      find_db_config:   830201.9 i/s - 1.97x  slower

============================== A few connections ===============================

Warming up --------------------------------------
      find_db_config    25.356k i/100ms
 fast_find_db_config    47.260k i/100ms
Calculating -------------------------------------
      find_db_config    248.648k (± 2.7%) i/s -      1.268M in   5.102833s
 fast_find_db_config    475.184k (± 3.0%) i/s -      2.410M in   5.077268s

Comparison:
 fast_find_db_config:   475184.1 i/s
      find_db_config:   248647.6 i/s - 1.91x  slower

=========================== Hundreds of connections ============================

Warming up --------------------------------------
      find_db_config   361.000  i/100ms
 fast_find_db_config     2.400k i/100ms
Calculating -------------------------------------
      find_db_config      3.622k (± 1.9%) i/s -     18.411k in   5.085694s
 fast_find_db_config     24.073k (± 2.0%) i/s -    122.400k in   5.086726s

Comparison:
 fast_find_db_config:    24073.0 i/s
      find_db_config:     3621.5 i/s - 6.65x  slower
2023-04-08 12:12:44 -04:00
Aaron Harpole
4a4cc21371 fix infinite recursion with foreign_key
In 15369fd we introduced the ability to infer the foreign_key for a model using `inverse_of`.

In some association configurations, such as when there is a `has_one` that is the inverse of another `has_one` association, this inference causes infinite recursion.

This addresses that by adding a param to `Reflection#foreign_key` to indicate whether to infer from `inverse_of`, and in `#derive_foreign_key` we explicitly disable this behavior when calling `#foreign_key` on the inverse association.
2023-04-07 10:42:34 -07:00
Aaron Patterson
a9506eb062
Merge pull request #46992 from ghiculescu/correct-after-commit-order
Run `after_commit` callbacks defined on models in the correct order
2023-04-07 10:12:35 -07:00
Rafael Mendonça França
fcf8c1bfaa
Merge pull request #47878 from bernardoamc/bc-update-sanitization-docs
Document string behaviour in ActiveRecord::Sanitization methods
2023-04-06 16:22:38 -04:00
Eileen M. Uchitelle
bdd0e0a255
Merge pull request #47879 from etiennebarrie/schema-migration-deprecation-typo
Fix typo in SchemaMigration deprecation
2023-04-06 15:41:50 -04:00
Étienne Barrié
e311e602e1 Fix typo in SchemaMigration deprecation 2023-04-06 21:37:12 +02:00
Bernardo de Araujo
a9b9bb097a Document string behaviour ActiveRecord::Sanitization
Without carefully reading examples or the source code it's not clear that
.sanitize_sql_for_conditions and .sanitize_sql_for_assignment methods won't
sanitize strings and will result in a no-op. This is an attempt to raise
awareness of this unexpected behaviour from a method aliased as `.sanitize_sql`.
2023-04-06 15:34:31 -04:00
notapatch
5b25375434 Add docs for Active Record validation with multiple contexts
The PR documents this change:
  https://github.com/rails/rails/pull/21535
Which allows multiple contexts to be validated:
  person.valid?([:create, :update])    # => true

The change isn't visible in the API documentation which this PR
fixes.
2023-04-06 16:13:38 +01:00
Eileen M. Uchitelle
c18e8ad69f
Merge pull request #47871 from adityapandit17/update-actiontext-dependencies
Fixed active-storage version in action text
2023-04-06 10:46:56 -04:00
Rafael Mendonça França
2f08f9ac2c
Merge pull request #47354 from etiennebarrie/deprecate-ActiveSupport-Deprecation-usage
Deprecate ActiveSupport::Deprecation singleton usage
2023-04-06 10:20:38 -04:00
Aditya Pandit
cf13f34262 Fixed activestorage version in action text 2023-04-06 19:22:26 +05:30
zzak
4cfaa225bb
Merge pull request #47869 from hachi8833/query_guides_order_desc
Doc: Add `:order` option for find_each docs to Query Guides [ci-skip]
2023-04-06 17:23:16 +09:00
zzak
4c3ad53e33
Merge pull request #47876 from zzak/nodoc-rails-conductor
Hide the rest of Rails::Conductor from API docs
2023-04-06 17:20:38 +09:00
zzak
87c73a3400
Hide the rest of Rails::Conductor from API docs 2023-04-06 17:00:18 +09:00
zzak
27ecbfeb42
Merge pull request #47875 from zzak/nodoc-rack
Hide Rack internals from API docs
2023-04-06 16:58:46 +09:00
zzak
5a4c212aca
Hide Rack internals from API docs 2023-04-06 16:39:38 +09:00
zzak
773ee2be1c
Merge pull request #47873 from zzak/activejob-basics-logging
Document verbose logging for Active Job
2023-04-06 08:53:28 +09:00
zzak
9f32c51d57
Document verbose logging for Active Job
Follow up to #47839
2023-04-06 08:39:20 +09:00
Eileen M. Uchitelle
47d0eacdaa
Merge pull request #47872 from Shopify/dup-for-cpk-ar-models
Reset composite primary key in `#dup`
2023-04-05 16:21:37 -04:00
Alex Ghiculescu
3bcd167c3e Run after_commit callbacks defined on models in the correct order 2023-04-05 14:21:33 -06:00
Nikita Vasilevsky
851fb27ae3 Reset composite primary key in #dup
This commit ensures that the composite primary key is reset when
`#dup` is called on an instance of an `ActiveRecord::Base` subclass.

For example:

```ruby
class TravelRoute < ActiveRecord::Base
  self.primary_key = [:origin, :destination]
end

route = TravelRoute.new(origin: "NYC", destination: "LAX")
route.dup # => #<TravelRoute origin: nil, destination: nil>
```
2023-04-05 19:58:34 +00:00
Vipul A M
f0148021b7
Merge pull request #47723 from kinduff/patch-1
Add context when changing secret_key_base
2023-04-05 20:30:29 +05:30
Alejandro AR
7a12fa129f Add context when changing secret_key_base
Fixes #47060

Adds additional context of what it will be lost in case the `secret_key_base` changes.
2023-04-05 08:49:01 -06:00
hachi8833
8fb80ac760 Add :order option to find_each docs in Query Guides 2023-04-05 17:28:07 +09:00
Petrik de Heus
2fc77e4502
Merge pull request #47840 from p8/docs/actionpack-intros
Add documentation intros for Action Controller and Action Dispatch
2023-04-05 08:27:05 +02:00
Yasuo Honda
2bf5f3ece2
Merge pull request #47855 from zzak/gemfile-duplicate-entry-warning
Fix duplicate Gemfile entry warning
2023-04-05 13:40:39 +09:00
zzak
4bcc7bc951
Fix duplicate Gemfile entry warning
Your Gemfile lists the gem rake (>= 13) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
2023-04-05 11:15:55 +09:00
John Hawthorn
70d3b8760f
Merge pull request #47863 from aharpole/fix-create-table-index-name-compatibility
Ensure pre-7.1 migrations use legacy index names when using create_table
2023-04-04 16:01:42 -07:00
Aaron Harpole
aa909b2444 allow pre-7.1 migrations to use legacy index names with create_table
Previously, if you were using a pre-7.1 migration and you were adding an index using `create_table`, the index would be named using the new index naming functionality introduced in  #47753.
2023-04-04 15:42:47 -07:00
John Hawthorn
6cd8dddb92
Merge pull request #47630 from bensheldon/action_mailer_around_delivery
Add `*_deliver` callbacks for Action Mailer
2023-04-04 14:58:15 -07:00
Eileen M. Uchitelle
946fc17c12
Merge pull request #47851 from stevehill1981/fix-mysql-check-constraint-schema-dump
Correctly dump check constraints for MySQL 8.0.16+
2023-04-04 14:44:41 -04:00
Steve Hill
ef14d13308 Correctly dump check constraints for MySQL 8.0.16+
If you're using MySQL 8.0.16+ and your database contains a table with
a check constraint, the first and last characters of the constraint
will be stripped when dumping the schema; this makes it impossible
to use check constraints in a MySQL 8.0 database with the `:ruby`
schema format; once dumped, they cannot be re-imported.

This is because, up until MySQL 8.0.16, all check constraints were
surrounded by an extra set of parentheses; this behaviour differed
from that presented by MariaDB, which handled them correctly thanks
to an engine check within the AbstractMySqlAdapter.

With this change, we only strip the parentheses if they are present,
which prevents the corruption of the constraint.

It is also possible that the exported check constraint will contain
invalid and unexpected whitespace characters; we handle that here too,
stripping out sequences of `\\` and `\n`, as well as any other
whitespace.
2023-04-04 18:30:42 +01:00
Valerii
7ab8ce3342
Update active_record_validations.md 2023-04-04 17:28:57 +03:00
Jean Boussier
c7f06b5113
Merge pull request #47844 from fatkodima/enqueue_all-logging
[ActiveJob] Add logging for `enqueue_all`
2023-04-04 12:47:20 +02:00
fatkodima
5ab2034730 [ActiveJob] Add logging for enqueue_all 2023-04-04 13:18:19 +03:00
Eileen M. Uchitelle
a1a026fb08
Merge pull request #47845 from zzak/notify-allow-failure
Notify job should not affect workflow result
2023-04-03 09:15:02 -04:00