Commit Graph

92266 Commits

Author SHA1 Message Date
Stephen Margheim 1e2c9048c4 Use SQLite `IMMEDIATE` transactions when possible.
Transactions run against the SQLite3 adapter default to IMMEDIATE mode to
improve concurrency support and avoid busy exceptions.

Fixture transactions use DEFERRED mode transactions as all `joinable`
transactions become DEFERRED transactions.
2024-07-26 09:02:08 +02:00
Jean Boussier ac0fa17eae
Merge pull request #52413 from ghiculescu/filter-param-card
Add `cvv` and `card_` as default parameters to filter out in new apps
2024-07-26 08:41:06 +02:00
Alex 53a52e3150 Add `cvv` and `cvc` as default parameters to filter out in new apps
In general you should not be posting credit card details to your server,
you should be using a processor like Stripe or Braintree.

But if you make a mistake in your form and *do* post a user's credit card number,
those details will get logged by default, even if your server doesn't use them.
Now you're potentially "storing card data" and so you have a whole bunch more legal
requirements to do it securely.

This PR adds `cvv` and `cvc` to the defaults for
[`ActiveSupport::ParameterFilter`](https://api.rubyonrails.org/v7.1.3.4/classes/ActiveSupport/ParameterFilter.html) for new apps.
This means that params with those names will not get logged by default.
This just changes the template for new apps; there's no changes made to existing apps.
2024-07-26 08:39:05 +02:00
Gannon McGibbon c40ff507b4 Deprecate multiple path route mapping
Drawing routes with multiple paths complicates route drawing enough to
warrant deprecation. Transitioning the routing mapper to use keywords
would result in a 1.25-1.5x improvement in speed, and it would be
substantially easier to do if we drop this feature. Most developers draw
one path per route, so this feature is likely seldom used. Developers
may also leverage with_options or a loop to make drawing easier.

```ruby
get "/users", "/other_path", to: "users#index"

get "/users", to: "users#index"
get "/other_path", to: "users#index"
```
2024-07-25 17:06:17 -05:00
Jean Boussier bfd3cfdbfc
Merge pull request #52339 from Shopify/fix-file-update-shared-tests
Simplify FileUpdateCheckerSharedTests
2024-07-25 18:46:24 +02:00
Jean Boussier 290b8069b9
Merge pull request #52329 from fatkodima/loaded-relation-batching-cpk
Fix loaded relation batching for models with composite primary keys
2024-07-25 14:37:13 +02:00
Jean Boussier b2754cc3e8
Merge pull request #52415 from Shopify/fix-rails-test-wrong-file
Fix test command to exit 1 on LoadError
2024-07-25 13:35:10 +02:00
Jean Boussier 0f6b122bb5 Fix test command to exit 1 on LoadError
Followup: https://github.com/rails/rails/pull/51005

We should only do the DidYouMean search if the file we failed
to load was the actual test file, not an underlying `require` call.

Also we should still raise an error so that the exit code is 1,
not 0.
2024-07-25 13:18:58 +02:00
Jean Boussier 77019de92e
Merge pull request #52412 from joshuay03/alternative-fix-for-48688
More robust fix for duplicate callbacks when singular child autosaves parent
2024-07-25 13:06:46 +02:00
Joshua Young 44dde3a173 More robust fix for duplicate callbacks when singular child autosaves parent 2024-07-25 18:17:38 +08:00
John Hawthorn 0db535f88d
Merge pull request #52402 from jhawthorn/avoid_extra_pings
Use raw connection for Trilogy more_results
2024-07-24 23:37:28 -07:00
John Hawthorn 4ff28e84b6 Always discard mysql2 multi-statement results
Same as Trilogy, using abandon_results! needs to be done on the same
original connection, and the best way to do that is inside raw_execute.
2024-07-24 22:59:16 -07:00
John Hawthorn 86f0259925 Always discard Trilogy multi-statement results
Previously we were trying to clear the extra results in a
with_raw_connection block, which caused some issues.

We never want to connect or reconnect here, we just need to drop any
results from a multi-statement query and that only makes sense to do on
the same connection we'd already used for the query.

Previously when a query was run which hit the query cache on a fresh,
non-sticky connection, the connection would perform its `verfiy!` before
calling next_result, resulting in a network round trip.
2024-07-24 22:57:33 -07:00
Gannon McGibbon cdaa1a39a3
Merge pull request #52408 from ghiculescu/as-find-signed-docs
Fix `ActiveStorage::Blob#find_signed!` docs
2024-07-25 00:21:22 -05:00
John Hawthorn 72741db81e
Merge pull request #52410 from jhawthorn/freeze_query_logs
Freeze modifications to ActiveRecord::QueryLogs
2024-07-24 00:04:32 -07:00
John Hawthorn 146ae32b85 Freeze modifications to ActiveRecord::QueryLogs
Tags and taggings build a cache when they are assigned, which means we
cannot support them being mutated. This freezes tags and taggings to
ensure they aren't changed after assignment.

This may not cover all cases, and per the previous PR we intend this to
be configured mostly via application.config, but it covers a case we
were making in our test suite and so should hopefully cover a mistake
users are somewhat likely to make.
2024-07-23 23:36:45 -07:00
John Hawthorn 8551d3d805
Merge pull request #52404 from ruyrocha/fix/sql-commenter-format-test
Fix specs for `QueryLogsTest#test_sql_commenter_format`.
2024-07-23 21:10:26 -07:00
Alex 33d80b274d Fix ActiveStorage::Blob#find_signed docs" 2024-07-24 11:08:00 +10:00
Gannon McGibbon a546cab8fc
Merge pull request #52407 from Shopify/regression_for_52303
Add regression test for development routes source mapping
2024-07-23 19:16:13 -05:00
Gannon McGibbon 2b5fdf54d6 Add regression test for development routes source mapping
Ensures route_source_locations setting is properly tested.
2024-07-23 18:52:11 -05:00
Gannon McGibbon 097d0f1088
Merge pull request #52406 from Shopify/revert_52303
Revert rails/rails#52303
2024-07-23 15:04:31 -05:00
Gannon McGibbon 561b6ce0e8 Revert rails/rails#52303
Reverts disabling source location drawing in development. It is used in
/rails/info/routes to point to route source locations.
2024-07-23 14:21:14 -05:00
Ruy R. ec635da1eb
Fix specs for `QueryLogsTest#test_sql_commenter_format`.
Address #52400.
2024-07-23 13:51:43 -03:00
Hartley McGuire 91f0bc494e
Merge pull request #52401 from ghiculescu/doc-always_write_cookie
Document `config.action_dispatch.always_write_cookie`
2024-07-23 13:59:00 +00:00
Alex 2dcfca850b
Document `config.action_dispatch.always_write_cookie` 2024-07-23 09:38:07 -04:00
Yasuo Honda a17aa6376d
Merge pull request #52397 from yahonda/follow_up_52392
Address ApplicationTests::QueryLogsTest errors
2024-07-23 10:03:06 +09:00
Yasuo Honda 8be777b917 Address ApplicationTests::QueryLogsTest errors
This commit addresses the following test errors since #52392

```ruby
$ bin/test test/application/query_logs_test.rb:271
Run options: --seed 33207

E

Error:
ApplicationTests::QueryLogsTest#test_controller_and_namespaced_controller_are_named_correctly,_legacy:
NoMethodError: undefined method `update_formatter' for module ActiveRecord::QueryLogs
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/railtie.rb:403:in `block (2 levels) in <class:Railtie>'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/lazy_load_hooks.rb:94:in `block in execute_hook'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/lazy_load_hooks.rb:87:in `with_execution_control'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/lazy_load_hooks.rb:92:in `execute_hook'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/lazy_load_hooks.rb:78:in `block in run_load_hooks'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/lazy_load_hooks.rb:77:in `each'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/lazy_load_hooks.rb:77:in `run_load_hooks'
    lib/rails/application/finisher.rb:94:in `block in <module:Finisher>'
    lib/rails/initializable.rb:32:in `instance_exec'
    lib/rails/initializable.rb:32:in `run'
    lib/rails/initializable.rb:61:in `block in run_initializers'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:350:in `each'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:350:in `call'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
    lib/rails/initializable.rb:60:in `run_initializers'
    lib/rails/application.rb:428:in `initialize!'
    /home/yahonda/src/github.com/rails/rails/tmp/d20240723-41340-lvtci5/app/config/environment.rb:5:in `<top (required)>'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    /home/yahonda/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    test/application/query_logs_test.rb:291:in `boot_app'
    test/application/query_logs_test.rb:276:in `block in <class:QueryLogsTest>'

bin/test test/application/query_logs_test.rb:271

Finished in 4.038127s, 0.2476 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
```
2024-07-23 09:22:54 +09:00
Hartley McGuire 2ea68a1111
Merge pull request #52375 from lairtonmendes/action_mailbox_mailgun
[ci skip] Update guide action_mailbox_basics.md mailgun tutorial
2024-07-22 23:53:14 +00:00
Petrik de Heus 0fbf310a34
Merge pull request #52389 from ghiculescu/patch-12
Active Storage guide: update the S3 CORS link [ci-skip]
2024-07-22 22:50:17 +02:00
Aaron Patterson 31fb496dca
Merge pull request #51996 from jackozi/exists_on_composite_keys
Fix `include?` on composite key relations
2024-07-22 11:37:59 -07:00
Aaron Patterson c2af8dbe37
Merge pull request #52186 from jackozi/missing-on-cpk
Fix `missing(:association)` and `associated(:association)` for composite primary keys
2024-07-22 11:36:55 -07:00
Jean Boussier b291408f93
Merge pull request #52392 from Shopify/perf-query-logs
Optimize ActiveRecord::QueryLogs
2024-07-22 15:56:04 +02:00
Jean Boussier 6fb612b5b6 Optimize ActiveRecord::QueryLogs
I noticed it showed up quite a bit on our production allocation
profiles. I tried to not break the interface, but in reality most
of it is private and it should only be configured through `application.config`.

main:

```
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) +YJIT [arm64-darwin23]

Total allocated: 1440 bytes (18 objects)

Calculating -------------------------------------
                 tag    521.552k (± 2.0%) i/s -      2.652M in   5.087518s
```

this branch:

```
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) +YJIT [arm64-darwin23]

Total allocated: 840 bytes (7 objects)

Calculating -------------------------------------
                 tag      1.070M (± 1.9%) i/s -      5.379M in   5.026878s
```

Benchmark:

```ruby
require 'bundler/inline'

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

  gem "benchmark-ips"
  gem "memory_profiler"
  gem "rails"
end

require "active_record"

ActiveRecord::QueryLogs.taggings = {
  some_handler: -> { "Handler" }
}
ActiveRecord::QueryLogs.tags = [
  :application,
  :some_handler,
  fixed_string: "fixed string",
  callback: ->(context) { "callback" },
]

ActiveSupport::ExecutionContext[:application] = "SuperApp"

ActiveRecord::QueryLogs.singleton_class.class_eval { public(:tag_content) }

ActiveRecord::QueryLogs.tag_content(:__connection__)

report = MemoryProfiler.report do
  ActiveRecord::QueryLogs.tag_content(:__connection__)
end

report.pretty_print

Benchmark.ips do |x|
  x.report("tag") { ActiveRecord::QueryLogs.tag_content(:__connection__) }
end
```
2024-07-22 15:28:47 +02:00
Jean Boussier 2fdf772715
Merge pull request #52204 from Shopify/update-ruby-vips
Update ruby-vips to fix a method redefinition warning
2024-07-22 09:55:22 +02:00
Jean Boussier 8af4d3594d Update ruby-vips to fix a method redefinition warning
Ref: https://github.com/libvips/ruby-vips/pull/388
2024-07-22 09:18:45 +02:00
Alex Ghiculescu 579dbff267
Active Storage guide: update the S3 CORS link 2024-07-22 16:32:16 +10:00
Lairton Mendes 65f3944cf9
Update action_mailbox_basics.md mailgun tutorial 2024-07-20 21:33:27 -03:00
John Hawthorn e0a9ef12b3
Merge pull request #52370 from jhawthorn/time_addition_deprecation
Combined time addition deprecation
2024-07-19 15:25:26 -07:00
John Hawthorn b669f15dd3
Merge pull request #52347 from jhawthorn/time_change_workaround
Workaround for Ruby UTC offset bug
2024-07-19 15:06:27 -07:00
John Hawthorn 3df676878a Avoid deprecation warning when raising
When calling + or since between two time objects we should avoid
emitting two deprecation messages and avoiding any deprecation messages
if the deprecated fallback raises an exception.
2024-07-19 14:50:22 -07:00
Nick Schwaderer efd0e6cceb Deprecate passing a Time object to Time#since
Ref: #52343

`Time.now.since(Time.now)` does not fail, but it returns a random future
date (currently in 2079).

This commit deprecates passing a Time object to Time#since until Rails
8.0, where it will raise a TypeError.
2024-07-19 14:25:08 -07:00
Nick Schwaderer 1f92ae6508 Deprecate adding two Time instances with ActiveSupport::TimeWithZone
Co-authored-by: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>

Ref: #52084

Subtracting two time instances results in a Float representing the
time between the instances.

Adding two time instances should not work, but it does.

```ruby
10.days.ago + 10.days.ago

```

 [This change](https://github.com/rails/rails/pull/52084/files#diff-aa0ae5ccf92f812f874b632afe70375c52772636f927fe6e34ffeaebf54af9d1L303) removed the rescue statement that had made this possible.
 Now, it is a breaking change to have made that easy mistake. This commit
 instead deprecates this change until Rails 8.0 and raises a deprecation
 warning when adding two Time instances.
2024-07-19 14:25:08 -07:00
Jean Boussier 9043dc5f08
Merge pull request #52366 from Shopify/require-hotloop
Avoid late require calls in potential hot spots
2024-07-19 23:21:20 +02:00
Jean Boussier 7836a16d7b Avoid late require calls in potential hot spots
Ref: https://bugs.ruby-lang.org/issues/20641

Granted it's an upstream bug, but even without the bug `require`
isn't cheap. `ConfigurationFile` isn't that hot of a spot in
production, but in Active Record test suite it's called for
almost every test so with this Ruby 3.3 bug it account for significant
part of the test suite runtime.
2024-07-19 22:33:30 +02:00
Eileen M. Uchitelle 89bf564c50
Merge pull request #52359 from fatkodima/fix-find_or_initialize_by-for-cpk-associations
Fix `find_or_initialize_by` for finding by associations with composite primary keys
2024-07-19 16:21:05 -04:00
fatkodima ad021ae6a6 Fix `find_or_initialize_by` for finding by associations with composite primary keys 2024-07-19 02:39:18 +03:00
John Hawthorn 44ca0f0f4d Workaround for Ruby UTC offset bug
Some Ruby versions have a bug when creating a Time object backed by a
timezone object where they create a fractional-second UTC offset.

For the added test, without this workaround, on Ruby 3.3.0:

      1) Failure:
    TimeExtCalculationsTest#test_change_preserves_fractional_seconds_on_zoned_time [./test/core_ext/time_ext_test.rb:528]:
    --- expected
    +++ actual
    @@ -1 +1,3 @@
    -"2005-01-30 00:00:00.99 -0500"
    +# encoding: US-ASCII
    +#    valid: true
    +"2005-01-30 00:00:00.99 -045959"

This is fixed in Ruby 3.3.1 and 3.2.4. We can remove the workaround when
we expect users to be on those versions or newer.
2024-07-18 00:33:50 -07:00
Petrik de Heus 55c4adeb36
Merge pull request #52350 from ashiksp/add-route-put-to-default-list
[ci skip] Added routes PUT to the default list (doc updates).
2024-07-17 15:00:39 +02:00
Ashik Salman 46eb303c67 Added routes PUT to the default list (doc updates). 2024-07-17 15:45:51 +05:30
Xavier Noria 1a9a4b0f51
Merge pull request #52349 from rails/fxn/before_configuration
Improve the docs of before_configuration
2024-07-17 09:17:00 +02:00