Commit Graph

84137 Commits

Author SHA1 Message Date
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
Benno Bielmeier
d4d3cca23c
Fix rdoc syntax for ActiveRecord::Associations::ClassMethods 2022-07-10 00:01:33 +02:00
Jonathan Hefner
b495b4eea1
Merge pull request #45550 from jonathanhefner/rename-urlsafe-to-url_safe
Rename `:urlsafe` option to `:url_safe`
2022-07-09 15:18:41 -05:00
Gannon McGibbon
6f20be9f97
Merge pull request #45553 from gmcgibbon/revert_model_pattern_matching
Revert "Provide pattern matching for ActiveModel"
2022-07-09 01:39:27 -04:00
Gannon McGibbon
17b4b8fd63 Revert "Provide pattern matching for ActiveModel"
This reverts commit 7e499b25acd5e1bfdd54ca2af66678b0ed05def1.
2022-07-09 00:13:23 -04:00
Jonathan Hefner
7094d0fc43 Rename :urlsafe option to :url_safe
Although Ruby provides `Base64.urlsafe_encode64` and
`Base64.urlsafe_decode64` methods, the technical term is "URL-safe",
with "URL" and "safe" as separate words.

For better readability, this commit renames the `:urlsafe` option for
`MessageEncryptor` and `MessageVerifier` to `:url_safe`.
2022-07-08 15:36:24 -05:00
Jonathan Hefner
d44e786d21 Add CHANGELOG entry for #44189 [ci-skip] 2022-07-08 14:54:42 -05:00
Gannon McGibbon
e240daa6cc
Merge pull request #45528 from gmcgibbon/job_parent_option
Add `--parent` option to job generator to specify parent class of job.
2022-07-07 16:57:35 -04:00
Jonathan Hefner
e722b74a92
Merge pull request #45470 from AlexB52/doc-full-message-format
Add Formatting Full Messages with I18n section in ActiveRecordValidations guides [ci-skip]
2022-07-07 13:33:36 -05:00
Alexandre Barret
0dd813c6da Add documentation to customize full_messages on ActiveModel and ActiveRecord
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-07 13:28:56 -05:00
Jonathan Hefner
d525b7848b
Merge pull request #45188 from tiramizoo/include-seconds-in-datetime-local-field
Add include_seconds option to datetime_local_field.
2022-07-07 13:16:24 -05:00
Yasuo Honda
cd08e6bcc4
Merge pull request #45537 from fatkodima/clear-memcache-in-tests
Clear cache in MemCacheStore tests
2022-07-07 08:41:33 +09:00
fatkodima
faacccdb75 Clear cache in MemCacheStore tests 2022-07-07 00:25:15 +03:00
Wojciech Wnętrzak
2dea9aebf2
Add include_seconds option to datetime_local_field.
This allows to omit seconds part in the input field, by passing `include_seconds: false`

It's a follow up to https://github.com/rails/rails/pull/41728
2022-07-06 22:27:04 +02:00
Jonathan Hefner
a6cb4531d5
Merge pull request #45520 from jonathanhefner/app_generator-implied-options
Improve generator implied option handling
2022-07-06 11:26:21 -05:00
Jonathan Hefner
0e77c83189
Merge pull request #45511 from ajporterfield/migration-index-update
Update migration near bottom of Active Record Basic guide [ci-skip]
2022-07-06 11:11:13 -05:00
Jonathan Hefner
54e3f8c381
Merge pull request #45521 from r7kamura/feature/fix-custom-behavior
Fix NoMethodError on custom ActiveSupport::Deprecation behavior
2022-07-06 10:57:57 -05:00