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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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?

@@ -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.

config/environments/production.rb Show resolved Hide resolved
@@ -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)

# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
return unless table_exists?(:active_storage_blobs)
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking we will want to use departure for this, and that the table should be added to https://github.com/otwcode/otwarchive/blob/master/.rubocop.yml#L84

Copy link
Contributor Author

@Bilka2 Bilka2 Feb 2, 2025

Choose a reason for hiding this comment

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

Our current DB schema has this:

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"

Meaning that we have foreign keys referencing active_storage_blobs (which is getting modified here), so if we use pt-online-schema-change / departure here, we run into issues with foreign keys:

When the tool renames the original table to let the new one take its place, the foreign keys “follow” the renamed table, and must be changed to reference the new table instead.

Departure currently sets --alter-foreign-keys-method auto.

config/environments/production.rb Show resolved Hide resolved
@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Review Gem Updates Has Migrations Contains migrations and therefore needs special attention when deploying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants