Commit Graph

84184 Commits

Author SHA1 Message Date
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
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
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
Yasuo Honda
f07d080c00
Merge pull request #44760 from lxxxvi/fix_rails_issue_db_fixtures_load_raises
`db:fixtures:load` raises in Postgres if there are foreign key constraints in a non-`public` schema
2022-07-20 01:21:54 +09:00
mario
e3bb10d0c3 prefix table_schema to ALTER TABLE ... VALIDATE CONSTRAINT for postgres
In Postgres there was an issue when calling `ActiveRecord::ConnectionAdapters::PostgreSQL::ReferentialIntegrity#all_foreign_keys_valid?` if there were multiple schemas with foreign key constraints, because the ALTER TABLE statement did not include the schema.

This commit adds the necessary schema prefix

```
ALTER TABLE [schema].[table_name] VALIDATE CONSTRAINT [constraint]
             ^^^^^^
```
2022-07-19 17:56:22 +02:00
Eileen M. Uchitelle
4ab6927b98
Merge pull request #45098 from richardboehme/active_storage-named-previews
Allow to use pre-defined variants for previews
2022-07-19 11:45:32 -04:00
Jonathan Hefner
9e0fe8e8bc
Merge pull request #45615 from jtmalinowski/fix-server-timing-overwrites
Prevent ActionDispatch::ServerTiming from overwriting existing header value
2022-07-19 10:33:43 -05:00
Richard Böhme
acf767dbd6 Allow to use pre-defined variants for previews
Previously, named variants could only be used when calling the
`variant` method on an attachment. For files that are not `variable?`
but `previewable?` those pre-defined variants could not be used.

With this patch, the methods `preview` and `representation` also allow
to be passed a variation name as a symbol.

    class User < ActiveRecord::Base
      has_one_attached :file do |attachable|
        attachable.variant :thumb, resize_to_limit: [100, 100]
      end
    end

    <%= image_tag user.file.representation(:thumb) %>
2022-07-19 16:59:52 +02:00
Eileen M. Uchitelle
bb68040de4
Merge pull request #45621 from eileencodes/fix-granular-swapping-for-primary_abstract_class
Fix granular swapping for primary_abstract_class
2022-07-19 09:54:43 -04:00
eileencodes
741d029606
Fix granular swapping for primary_abstract_class
In #45450 we stopped removing connections when establish_connection was
called and an identical connection existed in the pool. Unfortunately
this broke granular connection swapping for the primary_abstract_class
because the class stored in the pool was incorrect.

What was happening was connection for the writing role were getting
stored with the class ActiveRecord::Base and connections for the reading
role were getting ApplicationRecord (or whatever the app set as their
`primary_abstract_class`. If we made sure that the reading connections
also got ActiveRecord::Base that would break granular swapping for both
writing and reading because Active Record doesn't know whether you
wanted global swapping or granular swapping for prevent writes. This bug
only manifests on prevent writes because it's the only value we actually
lookup on the connection pool (because at the point we need it we don't
have access to self).

To fix this I've decided to update the class on the existing pool if it
doesn't match the owner_name passed. This is kind of gross I admit, but
it's safe because the way we find connections is on the
`connection_name`. The class is only stored so that the connection can
find it's `current_preventing_writes` value. This also required me to
move the ivar to an instance method for connection_class on the pool
because we don't want to cache the value and want to make sure we're
getting it from the pool config directly.
2022-07-19 08:22:35 -04:00
Eileen M. Uchitelle
a731c929c7
Merge pull request #45624 from sambostock/clear-job-buffer-on-teardown
Clear `JobBuffer` on `ActiveJob` test teardown
2022-07-19 08:22:01 -04:00
Jean Boussier
4e8e828291 Speedup ActionView::OutputBuffer
MRI has a lot of optimizations for string concatenation that
are only available when concatenating into a `String` instance.

Using a `String` subclass disable these optimizations.

The difference is even more important with YJIT.

So ideally we want the buffer not to be a String subclass.
Luckily, the Action View buffer is for internal use only, so
we can replace inheritance by composition without much work.

Benchmark:

```
ActionView::OutputBuffer:   147644.2 i/s
    optimized buffer:   228001.4 i/s - 1.54x  (± 0.00) faster
```

Source: https://gist.github.com/casperisfine/7199579a138e268fda71d6a91366af49

NB: That 50% faster figure is to be contextualized, it can radically change
from one template to the other, but is always faster.
2022-07-19 12:13:34 +02:00
Yasuo Honda
9596ec94ea
Merge pull request #45623 from fatkodima/fix-in_order_of-mysql-strings
Fix `QueryMethods#in_order_of` for non-integer columns in MySQL
2022-07-19 16:46:19 +09:00
Sam Bostock
eb4b540368
Clear JobBuffer on teardown
ActiveJob tests should be able to rely on a clean JobBuffer in each test.
2022-07-18 23:33:07 -04:00
fatkodima
c5ef2f4fb9 Fix QueryMethods#in_order_of for non-integer columns in MySQL 2022-07-19 02:24:58 +03:00
Jakub Malinowski
f075e0cf06
Prevent ActionDispatch::ServerTiming from overwriting existing header 2022-07-18 20:51:10 +02:00
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
Michael Siegfried
8fe1bd555f Accept nested functions in Dangerous Query Methods
Mailing list thread: https://discuss.rubyonrails.org/t/feature-proposal-accept-nested-functions-w-r-t-dangerous-query-methods/78650

*Summary*
I think there’s an opportunity to reduce additional false positives for
Dangerous Query Method deprecations/errors.

*Nested Functions*
Similar to https://github.com/rails/rails/pull/36448, it seems
reasonable to allow functions that accept other functions (e.g.
`length(trim(title))`).

*Background*
* PR accepting non-nested functions: https://github.com/rails/rails/pull/36448
* Deep background on deprecation and false positives: https://github.com/rails/rails/issues/32995
* Constants: `COLUMN_NAME` for the first and `COLUMN_NAME_WITH_ORDER` for both
2022-07-13 11:52:01 -07: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