Commit Graph

84269 Commits

Author SHA1 Message Date
Jonathan Hefner
e2d9747123 Fix update_all API doc [ci-skip]
Multi-line list items must be indented, and inline code must be quoted
using `+` or `<tt>`.  (RDoc does not support backticks.)
2022-07-26 10:38:37 -05:00
Jonathan Hefner
5e3d064630
Merge pull request #45657 from jonathanhefner/encrypted_file-post-hoc-key-file
Make `EncryptedFile` more memoization-friendly
2022-07-26 10:33:52 -05:00
Jonathan Hefner
8e3c315d12
Merge pull request #45487 from liljack/allow-pass-proc-to-validations-for-secure-password
Allow passing Hash on secure password validations
2022-07-26 10:32:29 -05:00
Kevin Jacoby
8804128ad4 Allow passing hash on secure password validations
I was running into a case where I didn't want to just disabled the
validations and add my own. In fact, I would very much like to keep the
default validation but just de-activate it on some scenario:
e.g. Inviting a user without having to set a password for them yet so
they can add it themselves later when they receive an email invitation
to finish setting up their account.

My understanding of the validations flag originally intended was to
just disabled them and if you needed something more custom, you could
run your own validations instead.

This would be an acceptable solution, but it would add more code to my
controller. Instead validations can receive a `Hash` wich is then use to
apply validations rules to `validate`.

This is just a suggestion, I am not sure if there is a need, and I am
aware this PR is probably far from perfect. Any feedback welcome.

EDIT: implemented changes as per feedback.
2022-07-26 10:11:43 -05:00
Jonathan Hefner
894686b8ef
Merge pull request #45653 from skipkayhil/rm-myapp-generator-tests
Remove unneeded subdirectories in generator tests
2022-07-26 10:06:36 -05:00
Matthew Draper
6693e5fc9a Deadlocks inside transactions are functionally not retryable
Even if we think the deadlocking query could be retried, the original
deadlock will have either broken or already rolled back our transaction.
2022-07-26 22:07:36 +09:30
Matthew Draper
3cc2f8ac77 Check #reconnect_can_restore_state? once, before running block
The block can't affect reconnectability, because we'll be re-running it
anyway.

Also, only #reconnect! once per query, to avoid squaring the total
number of permitted retries while attempting to query a pathologically
flakey server.
2022-07-26 22:07:35 +09:30
Matthew Draper
02f5de1bc9 Add retry handling to connection establishment too 2022-07-26 22:07:35 +09:30
Matthew Draper
da52b0d954 Separate two groups of retryable DB exceptions
Connectivity issues need a reconnect to be retried, but there are also
in-server errors that can also be retried (lock timeouts and deadlocks).

To handle this better, we move translation into #with_raw_connection:
it's a much better representation of the boundary between the underlying
adapter library and Active Record's abstractions anyway. (It doesn't
know about the query being run, though, so we let #log enrich that into
the exception later.)
2022-07-26 22:07:35 +09:30
Matthew Draper
b9f44e66ba Restore transactions in materialized state where appropriate
We may be restoring a connection after #with_raw_connection has already
passed #materialize_transactions, so it's important we eagerly return
things to exactly the state they had before.
2022-07-26 22:07:35 +09:30
Matthew Draper
129bfa193c Default most internal/schema queries to retryable 2022-07-26 22:07:35 +09:30
Matthew Draper
35d3ae3298 Switch Postgres statement pool to use the AR connection
We're still ultimately accessing the raw connection directly, but this
is necessary to keep the statement pool working across full reconnects.
2022-07-26 22:07:35 +09:30
Matthew Draper
542f0951dd Automatically reconnect to database mid-request
So far this is just infrastructure: no errors are considered retryable,
and no real queries are marked retryable.

Even in this state, we can drop connection verification from checkout,
and defer it until the first query is ready. But the more interesting
within-reach win will be when 'BEGIN' is retryable, and we can recognise
connectivity-related exceptions.
2022-07-26 22:07:35 +09:30
Yasuo Honda
f34fbadc10
Merge pull request #45662 from ghiculescu/patch-10
Mention `Arel.sql` in `update_all` docs [docs]
2022-07-26 14:14:42 +09:00
Hartley McGuire
337fa757d5
Remove unneeded subdirectories in generator tests
This pattern is useful in some cases, like moving the project folder
from myapp to myapp_moved, or testing generated behavior based on the
app name being hyphenated-app.

However, for the majority of cases this is not needed and adds
additional complexity to some assertion helpers. For example,
`assert_file` always expands paths relative to `destination_root`
instead of whatever the working directory is.
2022-07-25 17:39:46 -04:00
Alex Ghiculescu
82b8061ca2
Mention Arel.sql in update_all docs [docs]
This is needed when a string is input, to avoid type casting.

Fixes https://github.com/rails/rails/issues/45658
2022-07-25 15:14:21 -05:00
Gannon McGibbon
5a9113dc6b Clean up hook generator method when hook is removed
Removes "#{name}_generator" method for removed hooks introduced in #45315
2022-07-25 14:50:28 -05:00
Jonathan Hefner
71c0c81b47 Add CHANGELOG entry for #43688 [ci-skip] 2022-07-25 12:16:46 -05:00
Jonathan Hefner
2af4b98870 Make EncryptedFile more memoization-friendly
Prior to this commit, `EncryptedFile` would internally memoize when a
key file was non-existent.  This meant that a key file generated after
checking `encrypted_file.key.nil?` would not be recognized, unless a new
`EncryptedFile` instance was used.  (Though setting the key in a
designated environment variable instead would entirely bypass this
memoization.)

This commit changes `EncryptedFile` to only memoize when the key file
has been read.  Consequently, this commit memoizes the `EncryptedFile`
(or, specifically, `EncryptedConfiguration`) instance used by
`CredentialsCommand`.

This commit also adds more test coverage around key file generation for
`CredentialsCommand`.
2022-07-25 11:57:04 -05:00
Yasuo Honda
1755c5ac28
Merge pull request #45474 from fatkodima/disable_extension-cascade
Avoid removing a PostgreSQL extension when there are dependent objects
2022-07-25 20:55:48 +09:00
Yasuo Honda
6dd46e180e
Merge pull request #45655 from yahonda/strscan_304
Bump strscan to 3.0.4
2022-07-25 18:01:09 +09:00
Yasuo Honda
2e8381c8b2 Bump strscan to 3.0.4
This commit addresses bug_report_templates/action_controller_gem.rb failures.

```
% ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin22]
% cd guides/bug_report_templates
% ruby action_controller_gem.rb
Fetching gem metadata from https://rubygems.org/...........
... snip ...
Using rails 7.0.3.1
/Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:309:in `check_for_activated_spec!': You have already activated strscan 3.0.2, but your Gemfile requires strscan 3.0.4. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:25:in `block in setup'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/spec_set.rb:138:in `each'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/spec_set.rb:138:in `each'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:24:in `map'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:24:in `setup'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/inline.rb:71:in `block in gemfile'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/settings.rb:131:in `temporary'
	from /Users/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/inline.rb:55:in `gemfile'
	from action_controller_gem.rb:5:in `<main>'
%
```

strscan 3.0.4 has been released on July 23, 2022.
https://rubygems.org/gems/strscan/versions/3.0.4

Refer to https://github.com/rails/rails/pull/45052 for the similar change.
https://github.com/rubygems/rubygems/pull/5529
https://github.com/rubygems/rubygems/pull/5535
2022-07-25 17:41:00 +09:00
Jonathan Hefner
3d0686a9f6 Document ActiveSupport::EncryptedFile#key [ci-skip] 2022-07-24 18:43:19 -05:00
Jonathan Hefner
bbcf4bd3c6
Merge pull request #45652 from skipkayhil/test-for-system-test-update
Test skip_system_test being preserved after update
2022-07-24 16:51:44 -05:00
Hartley McGuire
3b667adcdf
Test skip_system_test being preserved after update
Followup to 37d0516

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-24 17:34:40 -04:00
Jonathan Hefner
76b0ef8d00
Merge pull request #45647 from skipkayhil/rm-redundant-updating-option
Remove duplicate 'updating' option from generator
2022-07-24 11:04:37 -05:00
Jonathan Hefner
7548d76bdc
Merge pull request #45648 from skipkayhil/fix-skip-system-test-update
Fix skip_system_test not being preserved in update
2022-07-23 21:13:44 -05:00
Jonathan Hefner
88921001ef
Merge pull request #45649 from skipkayhil/fix-extra-setup-newline
Fix extra line added to bin/setup in app:update
2022-07-23 21:00:50 -05:00
Hartley McGuire
f99f04a0c1
Fix extra line added to bin/setup in app:update
155b757 added some yarn commands to bin/setup for apps that are using
Node. However, the blank line between the added block and the
skip_active_record block results in an extraneous blank line added to
apps when running app:update.
2022-07-23 16:44:44 -04:00
Hartley McGuire
37d051612d
Fix skip_system_test not being preserved in update
Previously running app:update always would template an application.rb
file without the `config.generators.system_tests = nil` set, even for
applications that previously had it set.
2022-07-23 16:23:07 -04:00
Hartley McGuire
7fe640b8ca
Remove duplicate 'updating' option from generator
:update has been defined since a7adec9, and both options serve the same
purpose
2022-07-23 16:08:11 -04:00
Gannon McGibbon
97f13c2b82
Merge pull request #45627 from gmcgibbon/controller_generator_improvements
Controller generator improvements
2022-07-22 14:23:00 -05:00
fatkodima
515a9215d1 Avoid removing a PostgreSQL extension when there are dependent objects 2022-07-22 15:17:18 +03:00
Jonathan Hefner
789a3648f3
Merge pull request #45619 from pbstriker38/add_skip_nil_to_fetch_multi
Add `skip_nil:` support to `ActiveSupport::Cache::Store#fetch_multi`
2022-07-21 10:33:34 -05:00
Jonathan Hefner
aced3bb07b
Merge pull request #45569 from whyinzoo/whyinzoo-update-docs-ActiveSupport--Notification-monotonic-subscribe-for-pr
Add docs for ActiveSupport::Notifications.monotonic_subscribe [ci-skip]
2022-07-21 10:24:06 -05:00
Jean Boussier
17fd2edafb
Merge pull request #45618 from sambostock/active-job-big-decimal-serialization
Fix `BigDecimal `(de)serialization for `JSON` adapters
2022-07-21 15:58:28 +02:00
Ryan Zhou
e3de7872b1 better docs for ActiveSupport::Notifications.monotonic_subscribe 2022-07-21 03:20:33 +00:00
Gannon McGibbon
aaeffb2a56 Add --parent option to controller generator to specify parent class of controller.
Example:

`bin/rails g controller admin/users --parent=admin_controller` generates:

```ruby
class Admin::UsersController < AdminController
  # ...
end
```
2022-07-20 19:20:00 -05:00
Daniel Alfaro
1344031d7e Add skip_nil: support to ActiveSupport::Cache::Store#fetch_multi 2022-07-20 17:02:25 -05:00
Eileen M. Uchitelle
69078b0820
Merge pull request #45625 from adrianna-chang-shopify/ac-extract-build-create-table-definition
Extract `#build_create_table_definition` method
2022-07-20 09:25:05 -04:00
John Hawthorn
b5a758db1b
Avoid checking defined?(@html_safe) (#45620)
We should not need to check defined? here because we are only interested
in whether @html_safe is truthy or falsy.

We can  use an aliased attr_reader to make this even faster by skipping
both method dispatch.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2022-07-19 15:16:21 -07:00
Gannon McGibbon
bf4858722c Add more detailed description to controller generator
- Arguments are actions, not views
- URLs are routes
- Adds example for --skip-routes option
2022-07-19 16:13:42 -05:00
Sam Bostock
bc1f323338
Add ActiveJob::Serializers::BigDecimalSerializer
Previously, BigDecimal was listed as not needing a serializer.  However,
when used with an adapter storing the job arguments as JSON, it would get
serialized as a simple String, resulting in deserialization also producing
a String (instead of a BigDecimal).

By using a serializer, we ensure the round trip is safe.

During upgrade deployments of applications with multiple replicas making use of
BigDecimal job arguments with a queue adapter serializing to JSON, there exists
a possible race condition, whereby a "new" replica enqueues a job with an
argument serialized using `BigDecimalSerializer`, and an "old" replica fails to
deserialize it (as it does not have `BigDecimalSerializer`).

Therefore, to ensure safe upgrades, serialization will not use
`BigDecimalSerializer` until `config.active_job.use_big_decimal_serializer` is
enabled, which can be done safely after successful deployment of Rails 7.1.

This option will be removed in Rails 7.2, when it will become the default.
2022-07-19 15:31:41 -04:00
Jean Boussier
06e9fbd954
Merge pull request #45614 from Shopify/faster-output-buffer
Speedup ActionView::OutputBuffer
2022-07-19 21:08:49 +02:00
Jean Boussier
71c59c69f4
Merge pull request #44010 from siegfault/dangerous_query_method_allow_nested_functions
Accept nested functions in Dangerous Query Methods
2022-07-19 21:04:15 +02:00
Sam Bostock
b48b196910
Consolidate active_record 7.1 default loading
There appears to be no reason for these configs to be separate, and it makes
sense to group by framework.
2022-07-19 14:43:29 -04:00
Adrianna Chang
d747b0f132 Define #build_create_table_definition on connection adapter
Define API on connection adapter for building a TableDefinition.
The provided TableDefinition object offers insight into what a table
created using the migration method #create_table would look like, including
information on primary keys, column types, etc.

As a part of this PR, we extract TableDefinition#set_primary_key to handle
some of the primary key setting logic currently being performed in #create_table.
2022-07-19 14:22:54 -04:00
Eileen M. Uchitelle
fa7f977e2d
Merge pull request #45626 from eileencodes/remove-duplicate-code-in-rake-tasks
Remove duplicate code in dump task
2022-07-19 13:13:49 -04:00
Jonathan Hefner
166db2f2f6
Merge pull request #45574 from jonathanhefner/credentials-omit-secret_key_base-in-dev-and-test
Omit `secret_key_base` for dev and test credentials
2022-07-19 11:48:12 -05:00
eileencodes
31ab9cfe15
Remove duplicate code in dump task
The `_dump` task is private so it shouldn't be called by apps. Because
of this were establishing a connection to the db_config twice, once in
`_dump` and once in `dump`. There's no reason to do this since `_dump`
always calls `dump` and apps should not be calling `_dump`.
2022-07-19 12:42:30 -04:00