Update Rails to version 7.2.2 (#30391)

pull/2894/head
Matt Jankowski 2024-11-07 09:58:20 -05:00 committed by GitHub
parent 16b074d731
commit 41227aeb95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 118 additions and 224 deletions

View File

@ -6,7 +6,7 @@ ruby '>= 3.2.0'
gem 'propshaft'
gem 'puma', '~> 6.3'
gem 'rack', '~> 2.2.7'
gem 'rails', '~> 7.1.1'
gem 'rails', '~> 7.2.0'
gem 'thor', '~> 1.2'
gem 'dotenv'
@ -63,6 +63,7 @@ gem 'kaminari', '~> 1.2'
gem 'link_header', '~> 0.0'
gem 'mario-redis-lock', '~> 1.2', require: 'redis_lock'
gem 'mime-types', '~> 3.6.0', require: 'mime/types/columnar'
gem 'mutex_m'
gem 'nokogiri', '~> 1.15'
gem 'oj', '~> 3.14'
gem 'ox', '~> 2.14'

View File

@ -10,51 +10,46 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.4.2)
actionpack (= 7.1.4.2)
activesupport (= 7.1.4.2)
actioncable (7.2.2)
actionpack (= 7.2.2)
activesupport (= 7.2.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.4.2)
actionpack (= 7.1.4.2)
activejob (= 7.1.4.2)
activerecord (= 7.1.4.2)
activestorage (= 7.1.4.2)
activesupport (= 7.1.4.2)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.4.2)
actionpack (= 7.1.4.2)
actionview (= 7.1.4.2)
activejob (= 7.1.4.2)
activesupport (= 7.1.4.2)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
actionmailbox (7.2.2)
actionpack (= 7.2.2)
activejob (= 7.2.2)
activerecord (= 7.2.2)
activestorage (= 7.2.2)
activesupport (= 7.2.2)
mail (>= 2.8.0)
actionmailer (7.2.2)
actionpack (= 7.2.2)
actionview (= 7.2.2)
activejob (= 7.2.2)
activesupport (= 7.2.2)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (7.1.4.2)
actionview (= 7.1.4.2)
activesupport (= 7.1.4.2)
actionpack (7.2.2)
actionview (= 7.2.2)
activesupport (= 7.2.2)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack (>= 2.2.4, < 3.2)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.4.2)
actionpack (= 7.1.4.2)
activerecord (= 7.1.4.2)
activestorage (= 7.1.4.2)
activesupport (= 7.1.4.2)
useragent (~> 0.16)
actiontext (7.2.2)
actionpack (= 7.2.2)
activerecord (= 7.2.2)
activestorage (= 7.2.2)
activesupport (= 7.2.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.4.2)
activesupport (= 7.1.4.2)
actionview (7.2.2)
activesupport (= 7.2.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
@ -64,31 +59,33 @@ GEM
activemodel (>= 4.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (7.1.4.2)
activesupport (= 7.1.4.2)
activejob (7.2.2)
activesupport (= 7.2.2)
globalid (>= 0.3.6)
activemodel (7.1.4.2)
activesupport (= 7.1.4.2)
activerecord (7.1.4.2)
activemodel (= 7.1.4.2)
activesupport (= 7.1.4.2)
activemodel (7.2.2)
activesupport (= 7.2.2)
activerecord (7.2.2)
activemodel (= 7.2.2)
activesupport (= 7.2.2)
timeout (>= 0.4.0)
activestorage (7.1.4.2)
actionpack (= 7.1.4.2)
activejob (= 7.1.4.2)
activerecord (= 7.1.4.2)
activesupport (= 7.1.4.2)
activestorage (7.2.2)
actionpack (= 7.2.2)
activejob (= 7.2.2)
activerecord (= 7.2.2)
activesupport (= 7.2.2)
marcel (~> 1.0)
activesupport (7.1.4.2)
activesupport (7.2.2)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
aes_key_wrap (1.1.0)
@ -120,6 +117,7 @@ GEM
base64 (0.2.0)
bcp47_spec (0.2.1)
bcrypt (3.1.20)
benchmark (0.3.0)
better_errors (2.10.1)
erubi (>= 1.0.0)
rack (>= 0.9.0)
@ -613,20 +611,20 @@ GEM
rackup (1.0.0)
rack (< 3)
webrick
rails (7.1.4.2)
actioncable (= 7.1.4.2)
actionmailbox (= 7.1.4.2)
actionmailer (= 7.1.4.2)
actionpack (= 7.1.4.2)
actiontext (= 7.1.4.2)
actionview (= 7.1.4.2)
activejob (= 7.1.4.2)
activemodel (= 7.1.4.2)
activerecord (= 7.1.4.2)
activestorage (= 7.1.4.2)
activesupport (= 7.1.4.2)
rails (7.2.2)
actioncable (= 7.2.2)
actionmailbox (= 7.2.2)
actionmailer (= 7.2.2)
actionpack (= 7.2.2)
actiontext (= 7.2.2)
actionview (= 7.2.2)
activejob (= 7.2.2)
activemodel (= 7.2.2)
activerecord (= 7.2.2)
activestorage (= 7.2.2)
activesupport (= 7.2.2)
bundler (>= 1.15.0)
railties (= 7.1.4.2)
railties (= 7.2.2)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
@ -641,10 +639,10 @@ GEM
rails-i18n (7.0.10)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (7.1.4.2)
actionpack (= 7.1.4.2)
activesupport (= 7.1.4.2)
irb
railties (7.2.2)
actionpack (= 7.2.2)
activesupport (= 7.2.2)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
@ -755,6 +753,7 @@ GEM
scenic (1.8.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
securerandom (0.3.1)
selenium-webdriver (4.26.0)
base64 (~> 0.2)
logger (~> 1.4)
@ -838,6 +837,7 @@ GEM
unf_ext (0.0.9.1)
unicode-display_width (2.6.0)
uri (0.13.1)
useragent (0.16.10)
validate_email (0.1.6)
activemodel (>= 3.0)
mail (>= 2.2.5)
@ -946,6 +946,7 @@ DEPENDENCIES
mario-redis-lock (~> 1.2)
memory_profiler
mime-types (~> 3.6.0)
mutex_m
net-http (~> 0.5.0)
net-ldap (~> 0.18)
nokogiri (~> 1.15)
@ -984,7 +985,7 @@ DEPENDENCIES
rack-attack (~> 6.6)
rack-cors (~> 2.0)
rack-test (~> 2.1)
rails (~> 7.1.1)
rails (~> 7.2.0)
rails-controller-testing (~> 1.0)
rails-i18n (~> 7.0)
rdf-normalize (~> 0.5)

View File

@ -6,7 +6,7 @@ class Admin::SystemCheck::DatabaseSchemaCheck < Admin::SystemCheck::BaseCheck
end
def pass?
!ActiveRecord::Base.connection.migration_context.needs_migration?
!ActiveRecord::Base.connection_pool.migration_context.needs_migration?
end
def message

View File

@ -15,7 +15,9 @@ module Status::SafeReblogInsert
#
# The code is kept similar to ActiveRecord::Persistence code and calls it
# directly when we are not handling a reblog.
def _insert_record(values, returning)
#
# https://github.com/rails/rails/blob/v7.2.1.1/activerecord/lib/active_record/persistence.rb#L238-L263
def _insert_record(connection, values, returning)
return super unless values.is_a?(Hash) && values['reblog_of_id']&.value.present?
primary_key = self.primary_key
@ -30,16 +32,21 @@ module Status::SafeReblogInsert
# The following line departs from stock ActiveRecord
# Original code was:
# im.insert(values.transform_keys { |name| arel_table[name] })
# im = Arel::InsertManager.new(arel_table)
# Instead, we use a custom builder when a reblog is happening:
im = _compile_reblog_insert(values)
connection.insert(im, "#{self} Create", primary_key || false, primary_key_value, returning: returning).tap do |result|
with_connection do |_c|
connection.insert(
im, "#{self} Create", primary_key || false, primary_key_value,
returning: returning
).tap do |result|
# Since we are using SELECT instead of VALUES, a non-error `nil` return is possible.
# For our purposes, it's equivalent to a foreign key constraint violation
raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil?
end
end
end
def _compile_reblog_insert(values)
# This is somewhat equivalent to the following code of ActiveRecord::Persistence:

View File

@ -52,8 +52,6 @@ require_relative '../lib/action_dispatch/remote_ip_extensions'
require_relative '../lib/stoplight/redis_data_store_extensions'
require_relative '../lib/active_record/database_tasks_extensions'
require_relative '../lib/active_record/batches'
require_relative '../lib/active_record/with_recursive'
require_relative '../lib/arel/union_parenthesizing'
require_relative '../lib/simple_navigation/item_extensions'
Bundler.require(:pam_authentication) if ENV['PAM_ENABLED'] == 'true'
@ -61,10 +59,7 @@ Bundler.require(:pam_authentication) if ENV['PAM_ENABLED'] == 'true'
module Mastodon
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.1
# Explicitly set the cache format version to align with Rails version
config.active_support.cache_format_version = 7.1
config.load_defaults 7.2
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.

View File

@ -37,11 +37,6 @@ Rails.application.configure do
config.action_controller.forgery_protection_origin_check = ENV['DISABLE_FORGERY_REQUEST_PROTECTION'].nil?
ActiveSupport::Logger.new($stdout).tap do |logger|
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Generate random VAPID keys
Webpush.generate_key.tap do |vapid_key|
config.x.vapid_private_key = vapid_key.private_key
@ -51,6 +46,8 @@ Rails.application.configure do
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Disable caching for Action Mailer templates even if Action Controller
# caching is enabled.
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
@ -89,6 +86,9 @@ Rails.application.configure do
# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
config.generators.apply_rubocop_autocorrect_after_generate!
end
Redis.raise_deprecations = true

View File

@ -17,7 +17,6 @@ Rails.application.configure do
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_controller.asset_host = ENV['CDN_HOST'] if ENV['CDN_HOST'].present?
# Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment
# key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).
@ -26,8 +25,11 @@ Rails.application.configure do
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
# config.public_file_server.enabled = false
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"
config.asset_host = ENV['CDN_HOST'] if ENV['CDN_HOST'].present?
# Specifies the header that your server uses for sending files.
config.action_dispatch.x_sendfile_header = ENV['SENDFILE_HEADER'] if ENV['SENDFILE_HEADER'].present?
@ -37,6 +39,10 @@ Rails.application.configure do
# Allow to specify public IP of reverse proxy if it's needed
config.action_dispatch.trusted_proxies = ENV['TRUSTED_PROXY_IP'].split(/(?:\s*,\s*|\s+)/).map { |item| IPAddr.new(item) } if ENV['TRUSTED_PROXY_IP'].present?
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
# config.assume_ssl = true
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Skip http-to-https redirect for the default health check endpoint.
@ -46,14 +52,19 @@ Rails.application.configure do
},
}
# Info include generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
# want to log everything, set the level to "debug".
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym
# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
# "info" includes generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
# want to log everything, set the level to "debug".
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
# Use a different cache store in production.
config.cache_store = :redis_cache_store, REDIS_CONFIGURATION.cache
@ -61,6 +72,8 @@ Rails.application.configure do
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "mastodon_production"
# Disable caching for Action Mailer templates even if Action Controller
# caching is enabled.
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
@ -87,18 +100,8 @@ Rails.application.configure do
{ key: controller.signature_key_id } if controller.respond_to?(:signed_request?) && controller.signed_request?
end
# Use a different logger for distributed setups.
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_mailer.perform_caching = false
# E-mails

View File

@ -19,8 +19,6 @@ Rails.application.configure do
# loading is working properly before deploying your code.
config.eager_load = ENV['CI'].present?
config.assets_digest = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
@ -32,6 +30,8 @@ Rails.application.configure do
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Disable caching for Action Mailer templates even if Action Controller
# caching is enabled.
config.action_mailer.perform_caching = false
config.action_mailer.default_options = { from: 'notifications@localhost' }
@ -41,6 +41,10 @@ Rails.application.configure do
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Unlike controllers, the mailer instance doesn't have any context about the
# incoming request so you'll need to provide the :host parameter yourself.
config.action_mailer.default_url_options = { host: 'www.example.com' }
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
@ -58,7 +62,6 @@ Rails.application.configure do
# Raise exceptions for disallowed deprecations.
config.active_support.disallowed_deprecation = :raise
config.i18n.default_locale = :en
config.i18n.fallbacks = true
# Tell Active Support which deprecation messages to disallow.

View File

@ -1,65 +0,0 @@
# frozen_string_literal: true
# Add support for writing recursive CTEs in ActiveRecord
# Initially from Lorin Thwaits (https://github.com/lorint) as per comment:
# https://github.com/vlado/activerecord-cte/issues/16#issuecomment-1433043310
# Modified from the above code to change the signature to
# `with_recursive(hash)` and extending CTE hash values to also includes arrays
# of values that get turned into UNION ALL expressions.
# This implementation has been merged in Rails: https://github.com/rails/rails/pull/51601
module ActiveRecord
module QueryMethodsExtensions
def with_recursive(*args)
@with_is_recursive = true
check_if_method_has_arguments!(__callee__, args)
spawn.with_recursive!(*args)
end
# Like #with_recursive but modifies the relation in place.
def with_recursive!(*args) # :nodoc:
self.with_values += args
@with_is_recursive = true
self
end
private
def build_with(arel)
return if with_values.empty?
with_statements = with_values.map do |with_value|
raise ArgumentError, "Unsupported argument type: #{with_value} #{with_value.class}" unless with_value.is_a?(Hash)
build_with_value_from_hash(with_value)
end
# Was: arel.with(with_statements)
@with_is_recursive ? arel.with(:recursive, with_statements) : arel.with(with_statements)
end
def build_with_value_from_hash(hash)
hash.map do |name, value|
Arel::Nodes::TableAlias.new(build_with_expression_from_value(value), name)
end
end
def build_with_expression_from_value(value)
case value
when Arel::Nodes::SqlLiteral then Arel::Nodes::Grouping.new(value)
when ActiveRecord::Relation then value.arel
when Arel::SelectManager then value
when Array then value.map { |e| build_with_expression_from_value(e) }.reduce { |result, value| Arel::Nodes::UnionAll.new(result, value) }
else
raise ArgumentError, "Unsupported argument type: `#{value}` #{value.class}"
end
end
end
end
ActiveSupport.on_load(:active_record) do
ActiveRecord::QueryMethods.prepend(ActiveRecord::QueryMethodsExtensions)
end

View File

@ -1,51 +0,0 @@
# frozen_string_literal: true
# Fix an issue with `LIMIT` ocurring on the left side of a `UNION` causing syntax errors.
# See https://github.com/rails/rails/issues/40181
# The fix has been merged in ActiveRecord: https://github.com/rails/rails/pull/51549
# TODO: drop this when available in ActiveRecord
# rubocop:disable all -- This is a mostly vendored file
module Arel
module Visitors
class ToSql
private
def infix_value_with_paren(o, collector, value, suppress_parens = false)
collector << "( " unless suppress_parens
collector = if o.left.class == o.class
infix_value_with_paren(o.left, collector, value, true)
else
select_parentheses o.left, collector, false # Changed from `visit o.left, collector`
end
collector << value
collector = if o.right.class == o.class
infix_value_with_paren(o.right, collector, value, true)
else
select_parentheses o.right, collector, false # Changed from `visit o.right, collector`
end
collector << " )" unless suppress_parens
collector
end
def select_parentheses(o, collector, always_wrap_selects = true)
if o.is_a?(Nodes::SelectStatement) && (always_wrap_selects || require_parentheses?(o))
collector << "("
visit o, collector
collector << ")"
collector
else
visit o, collector
end
end
def require_parentheses?(o)
!o.orders.empty? || o.limit || o.offset
end
end
end
end
# rubocop:enable all

View File

@ -11,7 +11,7 @@ namespace :tests do
'3_3_0' => 2020_12_18_054746,
}.each do |release, version|
ActiveRecord::Tasks::DatabaseTasks
.migration_connection
.migration_connection_pool
.migration_context
.migrate(version)
Rake::Task["tests:migrations:populate_v#{release}"]

View File

@ -13,7 +13,7 @@ RSpec.describe Admin::SystemCheck::DatabaseSchemaCheck do
context 'when database needs migration' do
before do
context = instance_double(ActiveRecord::MigrationContext, needs_migration?: true)
allow(ActiveRecord::Base.connection).to receive(:migration_context).and_return(context)
allow(ActiveRecord::Base.connection_pool).to receive(:migration_context).and_return(context)
end
it 'returns false' do
@ -24,7 +24,7 @@ RSpec.describe Admin::SystemCheck::DatabaseSchemaCheck do
context 'when database does not need migration' do
before do
context = instance_double(ActiveRecord::MigrationContext, needs_migration?: false)
allow(ActiveRecord::Base.connection).to receive(:migration_context).and_return(context)
allow(ActiveRecord::Base.connection_pool).to receive(:migration_context).and_return(context)
end
it 'returns true' do