I've been having problems with thumbnail images displaying properly after upgrading my Rails 5.2 based ticketing system to Rails 6.0 The problem seems to have started after uncommentating the following lines in the config/initializers/new_framework_defaults_6_0.rb file:
Rails.application.config.active_storage.queues.analysis = :active_storage_analysis
Rails.application.config.active_storage.queues.purge = :active_storage_purge
Rails.application.config.active_storage.replace_on_assign_to_many = true
I'm calculating variants on the fly in my ERB template and linking to the original file using this code:
<%= link_to image_tag(image.representation(resize: "x150", auto_orient: true)), image %>
Which results in some strange behavior. Some of the thumbnails will generate fine and others will appear as broken references like this:
Here are the last few relevant lines from the log when that happens:
ActiveStorage::Blob Load (0.5ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", {a_unique_id}], ["LIMIT", 1]]
Disk Storage (0.1ms) Checked if file exists at key: variants/{a_unique_id}/{a_unique_id} (no)
Disk Storage (0.6ms) Downloaded file from key: {a_unique_id}
Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.5ms | Allocations: 817)
ActiveStorage::IntegrityError (ActiveStorage::IntegrityError):
activestorage (6.0.6.1) lib/active_storage/downloader.rb:39:in `verify_integrity_of'
Oddly, clicking through to the source file using the link I've constructed above always works and opens the original file just fine, even when clicking on the broken thumbnails. There's one more variable at play, this site gets a fairly large number of image upload daily, so I have a script running to downsample all images (using mogrify -qualiy) in the storage directory that have been created in the last 48 hours to save on disk space. One guess is that Rails 6.0 is calculating checksums stored in the ActiveStorage Blobs using the file size and 5.2 was not.
I'm less worried about fixing the already broken thumbnails than I am figuring out a fix for newly created tickets. Any insight is appreciated, I'm stumped at the moment.

Sounds like an issue with Active Storage's checksum verification process. This expects the file content to match its recorded checksum. If you're modifying images directly in the
storagedirectory, it could cause a mismatch.To fix, one option would be to disable the integrity check on variants. This should prevent an error being raised when the checksum doesn't match due to external modifications.
Alternatively, consider using Active Storage's variant method to resize images on-the-fly, which maintains the integrity of the original file.
For the existing broken thumbnails, you can reference this answer to recalculate checksums.