Commit Graph

84153 Commits

Author SHA1 Message Date
Jonathan Hefner
4e9fee9629
Merge pull request #45570 from whyinzoo/whyinzoo-update-docs-ActiveSupport--EncryptedFile-read-for-pr
Add docs for ActiveSupport::EncryptedFile#read [ci-skip]
2022-07-18 11:16:44 -05:00
Jonathan Hefner
bc0f07b93c
Merge pull request #45617 from ajporterfield/add-beginless-range-example-to-ar-querying-guide
Add endless range example to the Active Record Querying guide [ci-skip]
2022-07-18 11:11:44 -05:00
Andrew Porterfield
504887cff5 Add endless range example to the Active Record Querying guide 2022-07-18 10:43:03 -04:00
Yuta Uchida
a16c7c722e
Added default values to raise_delivery_errors guide (#45616) 2022-07-18 19:42:46 +05:30
Ryan Zhou
d64367e765 better docs for ActiveSupport::EncryptedFile#read 2022-07-16 04:04:42 +00:00
Jonathan Hefner
9994d38bc6
Merge pull request #45572 from fatkodima/fix-cached-missing-translations
Fix caching of missed translations
2022-07-15 15:06:29 -05:00
fatkodima
3822172c00 Fix caching of missed translations 2022-07-15 14:49:11 -05:00
Hartley McGuire
81c5c9971a
Fix extra changelog entry added in 959d46e (#45604)
The :urlsafe option was renamed to :url_safe in 7094d0f and the correct
entry is still below
2022-07-14 17:03:07 -07:00
matt swanson
959d46ef87
Add quarter method to date/time (#45009)
Co-authored-by: David Heinemeier Hansson <david@hey.com>
2022-07-14 16:43:52 -07:00
Yasuo Honda
4f818c7202
Merge pull request #45594 from skipkayhil/fix-test-yaml-permitted-classes
Fix testing changing yaml_column_permitted_classes
2022-07-14 08:52:41 +09:00
Hartley McGuire
1c13e6a47e
Fix testing changing yaml_column_permitted_classes
The default was changed in c2b96e3 but this test was not updated. Since
the assertion would pass even if the initializer failed, it needs to be
changed to something else.
2022-07-13 17:56:55 -04:00
Eileen M. Uchitelle
812bae8167
Merge pull request #45592 from eileencodes/remove-unnecessary-connection_handler-calls
Remove unnecessary or incorrect calls to connection_handler
2022-07-13 16:05:47 -04:00
eileencodes
baa90408a2
Remove unnecessary or incorrect calls to connection_handler
In an effort to find all the internal callers of `connection_handler` I
decided to remove any uses that are either:

1) Unnecessary - we can call what we need on Base or elsewhere without
going through the handler
2) Incorrect - there's a better way call the same thing. For exmaple
avoiding calling the ivar, and instead calling `send` on an existing
method.

Doing this will inform us what cases the connection handler is required
and how we can expand Base to provide everything an application or gem
could need without going through the handler. Reducing calls makes it
easier to replace or refactor in the future.
2022-07-13 14:26:04 -04:00
Jonathan Hefner
4dafe6a1eb
Merge pull request #45476 from bensheldon/defer_loading_activejob
Defer constant loading of `ActiveRecord::DestroyAssociationAsyncJob` via a String instead of a class constant
2022-07-13 13:06:39 -05:00
Ben Sheldon
8fceabd1e8 Defer constant loading of ActiveRecord::DestroyAssociationAsyncJob via a String instead of a class constant
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-13 11:58:20 -05:00
Jean Boussier
f002cada62
Merge pull request #45591 from Shopify/ar-store-hash-type
ActiveRecord::Store encode store as a regular Hash
2022-07-13 18:52:37 +02:00
Jean Boussier
05fdb3edfd ActiveRecord::Store encode store as a regular Hash
Fix: https://github.com/rails/rails/issues/45585

There's no benefit in serializing it as HWIA, it requires
to allow that type for YAML safe_load and takes more space.

We can cast it back to a regular hash before serialization.
2022-07-13 18:30:37 +02:00
Jean Boussier
84555afa2c Appease rubocop 2022-07-13 18:22:13 +02:00
Eileen M. Uchitelle
e7633661b1
Merge pull request #45586 from eileencodes/check-for-cte-support
Fix cases where CTE's are not supported
2022-07-13 12:12:42 -04:00
eileencodes
fde43b558a
Fix failing test with mysql 5.7
It turns out that buildkite CI was running with mysql 8 and that means
we weren't testing the behavior of mysql 5.7. This fixes a failing test
in main due to the difference in error message.
2022-07-13 12:11:20 -04:00
eileencodes
3c7e190ee8
Fix cases where CTE's are not supported
CTE's are not supported for MySQL versions below 8.0, so these tests
were failing locally for me on MySQL 5.7. While 5.7 is quite old, it's
still supported and used by many major Rails applications and we need a
check for support in our tests.

In addition to this PR I'll need to get a buildkite build running for
5.7. This wasn't caught earlier because our buildkite upgraded to 8.0.
2022-07-13 10:52:41 -04:00
Jean Boussier
05ae3faaf3
Merge pull request #45584 from etiennebarrie/allow-symbols-in-yaml-columns
Allow symbols in YAML columns
2022-07-13 15:02:07 +02:00
Étienne Barrié
c2b96e3e89 Allow Symbols by default in YAML serialized columns
In Ruby 3.1, YAML.load also defaults to allowing Symbols even it's using
safe_load.

https://docs.ruby-lang.org/en/3.1/Psych.html#method-c-load
2022-07-13 13:27:19 +02:00
Étienne Barrié
94d81c3c39 Remove unnecessary initializers
Active Record configs are already copied from the application with the
`active_record.set_configs` initializer.
2022-07-13 12:26:31 +02:00
Jeremy Daer
8d9d8013ca Preserve job.enqueued_at timestamp precision
* Allows instrumenters to more accurately deduce queue wait time
* Retains IS08601 compatibility

References #39698
2022-07-12 18:13:16 -07:00
Rafael Mendonça França
989de53d41
Merge pull request #45578 from natematykiewicz/yaml_safe_load_performance
Improve performance by removing respond_to? from runtime code
2022-07-12 17:28:44 -04:00
Nate Matykiewicz
f8f5c43c33
Improve performance by removing respond_to? from runtime code
respond_to? is inherently slow, and the YAML class won't change whether
it does or does not respond to unsafe_load, so just check it once
during file load, and define methods accordingly.
2022-07-12 16:04:14 -05:00
Eileen M. Uchitelle
2423fae772
Merge pull request #45576 from eileencodes/fix-pool-manager-ivar-name
Fix ivar name in PoolManager
2022-07-12 16:46:36 -04:00
Rafael Mendonça França
6e2e8c0d0f
Move configuration to the right section
And fix configuration name.

Both configs are for Active Record, not Active Storage.
2022-07-12 20:42:53 +00:00
eileencodes
cb04380019
Fix ivar name in PoolManager
This isn't a name to role mapping, it's a role to shard mapping. The
pool manager doesn't know it's name (only the connection handler does)
so it makes more sense to rename this ivar. Normally I wouldn't bother
since this is internal but since I'm doing a large refactor which
involves a lot of renaming, might as well get them all right.
2022-07-12 16:27:29 -04:00
Aaron Patterson
60258c8bf6
Merge branch 'main-sec'
* main-sec:
  Change ActiveRecord::Coders::YAMLColumn default to safe_load
2022-07-12 10:45:29 -07:00
Zack Deveau
611990f1a6
Change ActiveRecord::Coders::YAMLColumn default to safe_load
In Psych >= 4.0.0, load defaults to safe_load. This commit
makes the ActiveRecord::Coders::YAMLColum class use Psych safe_load
as the Rails default.

This default is configurable via ActiveRecord.use_yaml_unsafe_load

We conditionally fallback to the correct unsafe load if use_yaml_unsafe_load
is set to true. unsafe_load was introduced in Psych 4.0.0

The list of safe_load permitted classes is configurable via
ActiveRecord.yaml_column_permitted_classes

[CVE-2022-32224]
2022-07-12 09:26:46 -07:00
Eileen M. Uchitelle
3cbc7279fb
Merge pull request #45564 from eileencodes/replace-owner-and-spec-with-connection_name
Ensure connection_name is used everywhere
2022-07-12 09:21:20 -04:00
Jonathan Hefner
ce9d2a1160
Merge pull request #45544 from jonathanhefner/credentials-custom-templates
Support custom credentials templates
2022-07-11 16:42:48 -05:00
Jonathan Hefner
d7a4c913ec Support custom credentials templates
This commit adds support for in-app custom credentials templates.  When
a credentials file does not exist, `rails credentials:edit` will now try
to use `lib/templates/rails/credentials/credentials.yml.tt` to generate
the credentials file, before falling back to the default template.

This allows e.g. an open-source Rails app (which would not include
encrypted credentials files in its repo) to include a credentials
template, so that users who install the app will get a custom pre-filled
credentials file when they run `rails credentials:edit`.
2022-07-11 16:15:02 -05:00
Jonathan Hefner
cd4292f5c1
Merge pull request #45543 from jonathanhefner/credentials-secret_key_base-for-new-environment
Generate `secret_key_base` for all new credentials
2022-07-11 16:10:01 -05:00
Jonathan Hefner
915776ad04 Generate secret_key_base for all new credentials
Currently, when `config/credentials.yml.enc` is generated by
`CredentialsGenerator`, it includes a `secret_key_base` for convenience.
However, because `config/credentials/#{environment}.yml.enc` files are
generated by a different generator (`EncryptedFileGenerator`), they do
not include a `secret_key_base`.

This commit revises `CredentialsGenerator` to be more generator-like,
and changes `rails credentials:edit` to use it for generating both
`config/credentials.yml.enc` and `config/credentials/#{environment}.yml.enc`
files, thereby always including a `secret_key_base`.
2022-07-11 15:36:54 -05:00
Jonathan Hefner
189356bd24
Merge pull request #45563 from diegomichel/fixes-rubydoc-info-links
Fixes rubydoc links [ci-skip]
2022-07-11 14:19:29 -05:00
Diego Michel
eeb14214fd Fixes rubydoc links
Uses gem version of documentation instead of repo version

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-11 12:58:12 -06:00
eileencodes
3dffb0da78
Ensure connection_name is used everywhere
Looking at connection management we were using `spec_name`,
`spec`, `owner_name`, `owner` and `connection_specification_name` to all mean
the "string representation of the name we use to lookup the connection".

In most applications this is the string representation of the class that
established the connection. In some rarer cases this is represented by
either passing a string to `owner_name` on `establish_connection` or
passing a config as a symbol which gets turned into an `owner_name`.
This behavior is undocumented and legacy, in most cases no longer
necessary. However I know that it is still in use so I'm going to slowly
work on replacing it so the behavior is less confusing.

For now this PR simply renames all the interal words to mean "string
that established the connection" to `connection_name`. In my next PR
I'll address the public APIs around `connection_specification_name` on
`Base` and `owner_name` on `ConnectionHandler`.

Note that the instrumentation in `establish_connection` is private
(denoted by the !), so it is safe to change without warning. Everything
else is internal naming or part of a private API.
2022-07-11 13:44:57 -04:00
Yasuo Honda
a3475f07cc
Merge pull request #45559 from skipkayhil/fix-missing-changelog-authors
Add missing CHANGELOG authors
2022-07-11 15:31:19 +09:00
Hartley McGuire
5458571254
Add missing CHANGELOG authors
Ref 44a2971
Ref 9f0b8eb
2022-07-11 01:43:32 -04:00
Yasuo Honda
2cf8f37d50
Merge pull request #44601 from ghiculescu/time-zone-aware-type-postgres
Add `timestamptz` as a time zone aware type for PostgreSQL
2022-07-11 08:23:04 +09:00
Jonathan Hefner
a72a65bc49
Merge pull request #45557 from ghiculescu/patch-10
Missing author on changelog entry for #44189 [ci-skip]
2022-07-10 15:53:00 -05:00
Alex Ghiculescu
2f52610c49
Missing author on changelog entry for #44189
cc @jonathanhefner
2022-07-10 15:33:50 -05:00
Alex Ghiculescu
75c406d774 Make timestamptz a time zone aware type for Postgres
https://github.com/rails/rails/pull/41395 added support for the `timestamptz` type on the Postgres adapter.

As we found [here](https://github.com/rails/rails/pull/41084#issuecomment-1056430921) this causes issues because in some scenarios the new type is not considered a time zone aware attribute, meaning values of this type in the DB are presented as a `Time`, not an `ActiveSupport::TimeWithZone`.

This PR fixes that by ensuring that `timestamptz` is always a time zone aware type, for Postgres users.
2022-07-10 15:32:18 -05:00
Petrik de Heus
81d6012f4f
Merge pull request #45538 from hexdevs/custom-validator-loaded-note
Clarify how `EachValidator` is automatically loaded [ci-skip]
2022-07-10 10:46:36 +02:00
Ryuta Kamizono
c3fd9f1776 Remove reverted CHANGELOG entry [ci-skip]
Follow up to #45553.
2022-07-10 10:02:27 +09:00
Stefanni Brasil
ecbca0cb1e Make Custom Validators example more clear
The Active Record Validations guide use `Person < ApplicationRecord`
in all examples. When reading about Custom Validators, one of the
examples had a different configuration. By using the same example
everywhere, this change helps the user save time and feel more confident
using the feature.
2022-07-09 17:56:51 -07:00
Jonathan Hefner
b9f1d406f6
Merge pull request #45555 from bbenno/main
Fix rdoc for ActiveRecord::Associations::ClassMethods [ci-skip]
2022-07-09 17:22:54 -05:00