title: URL to images stored in S3 changes after updating Rails to 6.1.3.2
body: <p>Please excuse me for my poor English.</p>
  <p>In our system, we use ActiveStorage in Rails to manage images.
  This time, we updated Rails from 6.0.3.6 to 6.1.3.2 and encountered the following problem.
  I would like to know the cause and how to solve the problem.</p>
  <h1>Problems that occurred</h1>
  <p>The URL to the images stored in S3 changed before and after the update, and images stored before the update could not be displayed.</p>
  <h2>Steps to reproduce</h2>
  <ul>
  <li>Update Rails from 6.0.3.6 to 6.1.3.2</li>
  <li>Run <code>rails active_storage:update</code></li>
  <li>Run <code>rails db:migrate</code></li>
  <li>Open the page with the images that were saved before the Rails update</li>
  </ul>
  <p><strong>Source Code</strong></p>
  <pre><code>class Image &lt; ApplicationRecord
    include ActiveStorageSupport::SupportForBase64
  
    after_commit :process_variants
  
    has_one_base64_attached :file
  
    def provider_file_url
      key = file.variant(resize_to_limit: [500, 500]).key
  
      &quot;#{ENV[‘BASE_URL']}/#{key}&quot;
    end
  
    private
  
    def process_variants
      return unless file.attachment
  
      file.variant(resize_to_limit: [500, 500]).processed
    rescue StandardError
      nil
    end
  end
  
  # Call URL
  image_instance.provider_file_url
  </code></pre>
  <h2>Expected behavior</h2>
  <p>The same URL is generated before and after the Rails update.</p>
  <h2>Actual behavior</h2>
  <p>Generated URLs are different before and after Rails update.</p>
  <p><strong>Example：</strong></p>
  <p>Before update</p>
  <pre><code>https://sample.net/variants/zvd2z2dafhrht3yy99l8w9zw54h8/3a8af9a41326f81dcc439e015ab90b5d9d078e2b00dd7d021c4d4ee650e5c6e0
  </code></pre>
  <p>After update</p>
  <pre><code>https://sample.net/variants/zvd2z2dafhrht3yy99l8w9zw54h8/ac54d233b136b9f97f4d984f115d2e1c4695c2a0a3994c28d347637301445431
  </code></pre>
  <h2>What I investigated</h2>
  <p>I compared the behavior of ActiveStorage 6.0.3.6 and 6.1.3.2, and found the following differences.
  However, I have not been able to get to the cause of this.</p>
  <p><strong>Added debug code in two places ↓.</strong></p>
  <p>① initialize of <code>ActiveStorage::Variant</code> class (<a href="https://github.com/rails/rails/blob/75ac626c4e21129d8296d4206a1960563cc3d4aa/activestorage/app/models/active_storage/variant.rb#L58" rel="nofollow noreferrer">source code</a>)</p>
  <pre><code>class ActiveStorage::Variant
    # omitted
  
    def initialize(blob, variation_or_variation_key)
      p '-----------------------------------------------------------------------------------------'
      p 'blob'
      p blob
      p 'variation_or_variation_key'
      p variation_or_variation_key
      p '-----------------------------------------------------------------------------------------'
  
      @blob, @variation = blob, ActiveStorage::Variation.wrap(variation_or_variation_key)
    end
  
    # omitted
  end
  </code></pre>
  <p>② <code>encode</code> method of <code>ActiveStorage::Variation</code> class (<a href="https://github.com/rails/rails/blob/75ac626c4e21129d8296d4206a1960563cc3d4aa/activestorage/app/models/active_storage/variation.rb#L39" rel="nofollow noreferrer">source code</a>)</p>
  <pre><code>class ActiveStorage::Variation
    attr_reader :transformations
  
    class &lt;&lt; self
      # omitted
  
      def encode(transformations)
        p '-----------------------------------------------------------------------------------------'
        p transformations
        p '-----------------------------------------------------------------------------------------'
  
        ActiveStorage.verifier.generate(transformations, purpose: :variation)
      end
    end
  
    # omitted
  end
  </code></pre>
  <p><strong>Run provider_file_url method</strong></p>
  <p>①</p>
  <p>ActiveStorage<code>6.0.3.6</code></p>
  <pre><code>&quot;-----------------------------------------------------------------------------------------&quot;
  &quot;blob&quot;
  #&lt;ActiveStorage::Blob id: ９９９, key: &quot;zvd2z2dafhrht3yy99l8w9zw54h7&quot;, filename: &quot;sample.jpg&quot;, content_type: &quot;image/jpeg&quot;, metadata: {&quot;identified&quot;=&gt;true, &quot;analyzed&quot;=&gt;true}, byte_size: 15789, checksum: &quot;NwtXS6KRF1ty1WxXMicUew==&quot;, created_at: &quot;2021-06-02 08:32:15&quot;&gt;
  &quot;variation_or_variation_key&quot;
  {:resize_to_limit=&gt;[500, 500]}
  &quot;-----------------------------------------------------------------------------------------&quot;
  </code></pre>
  <p>ActiveStorage<code>6.1.3.2</code></p>
  <pre><code>&quot;-----------------------------------------------------------------------------------------&quot;
  &quot;blob&quot;
  #&lt;ActiveStorage::Blob id: 999, key: &quot;zvd2z2dafhrht3yy99l8w9zw54h7&quot;, filename: &quot;sample.jpg&quot;, content_type: &quot;image/jpeg&quot;, metadata: {&quot;identified&quot;=&gt;true, &quot;analyzed&quot;=&gt;true}, byte_size: 15789, checksum: &quot;NwtXS6KRF1ty1WxXMicUew==&quot;, created_at: &quot;2021-06-02 17:32:15.000000000 +0900&quot;, service_name: &quot;amazon&quot;&gt;
  &quot;variation_or_variation_key&quot;
  #&lt;ActiveStorage::Variation:0x00007fa2db230430 @transformations={:format=&gt;&quot;jpg&quot;, :resize_to_limit=&gt;[500, 500]}&gt;
  &quot;-----------------------------------------------------------------------------------------&quot;
  </code></pre>
  <p>②</p>
  <p>ActiveStorage<code>6.0.3.6</code></p>
  <pre><code>&quot;-----------------------------------------------------------------------------------------&quot;
  {:resize_to_limit=&gt;[500, 500]}
  &quot;-----------------------------------------------------------------------------------------&quot;
  </code></pre>
  <p>ActiveStorage<code>6.1.3.2</code></p>
  <pre><code>&quot;-----------------------------------------------------------------------------------------&quot;
  {:format=&gt;&quot;jpg&quot;, :resize_to_limit=&gt;[500, 500]}
  &quot;-----------------------------------------------------------------------------------------&quot;
  </code></pre>
  <p>As a test, I added a process to remove the :format key in the encode method, and now the URL is generated as before the update.</p>
  <h2>System configuration</h2>
  <h3>Before update</h3>
  <p><strong>Rails</strong>: 6.0.3.6</p>
  <p><strong>Ruby</strong>: 2.6.6</p>
  <p><strong>Gemfile.lock</strong></p>
  <pre><code>    activestorage (6.0.3.6)
        actionpack (= 6.0.3.6)
        activejob (= 6.0.3.6)
        activerecord (= 6.0.3.6)
        marcel (~&gt; 1.0.0)
  </code></pre>
  <h3>After update</h3>
  <p><strong>Rails version</strong>: 6.1.3.2</p>
  <p><strong>Ruby version</strong>: 2.6.6</p>
  <p><strong>Gemfile.lock</strong></p>
  <pre><code>    activestorage (6.1.3.2)
        actionpack (= 6.1.3.2)
        activejob (= 6.1.3.2)
        activerecord (= 6.1.3.2)
        activesupport (= 6.1.3.2)
        marcel (~&gt; 1.0.0)
        mini_mime (~&gt; 1.0.2)
  </code></pre>