Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6893 Upgrade gems and configs to Rails 7.1.x #5039

Merged
merged 12 commits into from
Feb 15, 2025

Conversation

Bilka2
Copy link
Contributor

@Bilka2 Bilka2 commented Jan 29, 2025

Issue

https://otwarchive.atlassian.net/browse/AO3-6893

Purpose

Upgrade to Rails 7.1. Should go in after Ruby 3.2 and AO3-6892.

Testing Instructions

Refer to Jira.

Credit

Bilka

@github-actions github-actions bot added Has Migrations Contains migrations and therefore needs special attention when deploying Gem Updates Awaiting Review labels Jan 29, 2025
Comment on lines +16 to +19
.includes(blocked: [:pseuds, { default_pseud: { icon_attachment: { blob: {
variant_records: { image_attachment: :blob },
preview_image_attachment: { blob: { variant_records: { image_attachment: :blob } } }
} } } }])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change and the same one in muted/users_controller.rb is based on the same change in Active Storage, because this is a copy of the with_attached_* scope: https://github.com/rails/rails/blob/v7.0.8.3/activestorage/lib/active_storage/attached/model.rb -> https://github.com/rails/rails/blob/v7.1.5.1/activestorage/lib/active_storage/attached/model.rb (track_variants is true for us)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 7.1 so we should be able to re-enable these lines:

# Rails doesn't seem to want to include variants, so this won't work right now.
# We can revisit when https://github.com/rails/rails/pull/49231 is released OR we upgrade to Rails 7.1
# blocked.default_pseud.icon.attach(io: File.open(Rails.root.join("features/fixtures/icon.gif")), filename: "icon.gif", content_type: "image/gif")

and

# Rails doesn't seem to want to include variants, so this won't work right now.
# We can revisit when https://github.com/rails/rails/pull/49231 is released OR we upgrade to Rails 7.1
# muted.default_pseud.icon.attach(io: File.open(Rails.root.join("features/fixtures/icon.gif")), filename: "icon.gif", content_type: "image/gif")

However, with these lines restored, I didn't get any test failures on the current main branch / Rails 7.0. Not sure why yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something related to these comments got lost in the whole active storage PR, it was quite large and there were changes to the related scope after these comments were added. I'll just uncomment the tests and we can be happy that they pass now, I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good? news:

The test changes behaviour based on whether we show the images via the proxy url or with processed.url, it fails only when using processed.url. This matches the documentation. So AO3-6898 temporarily broke it, then AO3-6900 fixed it again.

I reverted AO3-6900 locally to try to make the test work, but sadly it doesn't seem to want to behave, no matter what includes I use. According to bullet, the includes are effective when viewing the blocked user index in a browser, but the test still fails.

I recall that we also had problems with this in the initial Active Storage PR. So I'll go ahead and disable the test again and note that using processed.url may result in N+1 queries. Hopefully we can just stick with the proxy url.

@@ -899,7 +899,7 @@ def build_options(params)
external_coauthor_name: params[:external_coauthor_name],
external_coauthor_email: params[:external_coauthor_email],
language_id: params[:language_id]
}
}.compact_blank!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the nokogiri update, when encoding defaulted to empty string here, that empty string was getting used as the encoding instead of the actual encoding of the downloaded story. Getting rid of the empty string via compact_blank! makes it fall back to the encoding of the downloaded story as expected.

@@ -84,7 +84,7 @@ def document(object)
json_object = object.as_json(
root: false,
only: [
:id, :created_at, :bookmarkable_type, :bookmarkable_id, :user_id,
:id, :created_at, :bookmarkable_type, :bookmarkable_id,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This user_id was duplicate with the one in the merge call later (as_json uses string keys, the merge uses symbols, so it wasn't getting overwritten by the merge). Something changed in the json serialization for Elasticsearch so it wasn't getting rid of this duplicate "user_id": nil anymore, so deleting it here is the fix.

Comment on lines +145 to +147

# Use secret from archive config
config.secret_key_base = ArchiveConfig.SESSION_SECRET
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -99,7 +103,6 @@ class Application < Rails::Application
"X-Frame-Options" => "SAMEORIGIN",
"X-XSS-Protection" => "1; mode=block",
"X-Content-Type-Options" => "nosniff",
"X-Download-Options" => "noopen",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is suggested by the update script. It worsens Internet Explorer support.

Copy link
Member

@brianjaustin brianjaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some tests failing so not my final review, but here are my initial thoughts. (And if you have time, it might be nice to convert the failing tests to RSpec instead of minitest, but that's out of scope so not a big deal either way)

@Bilka2
Copy link
Contributor Author

Bilka2 commented Jan 29, 2025

The tests seem to be flaky, they didn't fail on the commit with the active storage changes, just the one with the robocop changes. I also had them fail on master on my fork, and then pass after a re-run: https://github.com/Bilka2/otwarchive/actions/runs/13028412099/attempts/1 I won't have time to investigate why they're flaky before Sunday, if someone else wants to have a look.

And I figured I know better than rubocop for the rest of the reviewdog complaints/didn't want to change the generated migrations.

@@ -739,7 +739,7 @@ PERCONA_ARGS: >
--max-load Threads_running=15
--critical-load Threads_running=100
--set-vars innodb_lock_wait_timeout=2
--alter-foreign-keys-method=auto
--alter-foreign-keys-method=drop_swap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like @zz9pzza or @brianjaustin to confirm that this option is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the pt-online-schema-change manpage:

           drop_swap
               Disable foreign key checks (FOREIGN_KEY_CHECKS=0), then drop the original table before renaming the new
               table into its place. This is different from the normal method of swapping the old and new table, which
               uses an atomic "RENAME" that is undetectable to client applications.

               This method is faster and does not block, but it is riskier for two reasons.  First, for a short time
               between dropping the original table and renaming the temporary table, the table to be altered simply
               does not exist, and queries against it will result in an error.  Secondly, if there is an error and the
               new table cannot be renamed into the place of the old one, then it is too late to abort, because the old
               table is gone permanently.

               This method forces "--no-swap-tables" and "--no-drop-old-table".

The last line seems a bit contradictory to the initial paragraph, but we'll want to be aware that this might leave us with tables to clean up (although we haven't always done that in the past so...) Also noting that this setting is overridden by Ansible, so we'll need to change that as well.

Overall, I think this is OK. If we're particularly worried about a table going wonky, we have backups and can also disable replication for a bit to have a "good" copy to fall back to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ended up using rebuild_constraints instead (#5066).

Comment on lines -51 to +55
# The default locale is :en and all translations from config/locales/**/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join("config/locales/**/*.{rb,yml}")]
# The default locale is :en.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The load_path configuration defaults to this since Rails 7.0: https://guides.rubyonrails.org/v7.1/configuring.html#config-i18n-load-path

@brianjaustin brianjaustin added Reviewed: Ready to Merge Has Production Config Changes Modifies the config file and needs special attention when deploying and removed Awaiting Review labels Feb 6, 2025
@brianjaustin brianjaustin merged commit e44c571 into otwcode:master Feb 15, 2025
29 checks passed
@Bilka2 Bilka2 deleted the AO3-6893-rails-7-1-x branch February 15, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gem Updates Has Migrations Contains migrations and therefore needs special attention when deploying Has Production Config Changes Modifies the config file and needs special attention when deploying Reviewed: Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants