You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open a transaction (using #transaction or #with_lock)
Attach a file
Call #with_lock while in the same transaction
Close the transaction
Try to download the attachment
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"gem"rails",'~> 7.2'# If you want to test against edge Rails replace the previous line with this:# gem "rails", github: "rails/rails", branch: "main"gem'securerandom'gem"sqlite3"endrequire"active_record/railtie"require"active_storage/engine"require"minitest/autorun"ENV["DATABASE_URL"]="sqlite3::memory:"classTestApp < Rails::Applicationconfig.load_defaultsRails::VERSION::STRING.to_fconfig.root=__dir__config.hosts << "example.org"config.eager_load=falseconfig.session_store:cookie_store,key: "cookie_store_key"config.secret_key_base="secret_key_base"config.logger=Logger.new($stdout)Rails.logger=config.loggerconfig.active_storage.service=:localconfig.active_storage.service_configurations={local: {root: Dir.tmpdir,service: "Disk"}}endRails.application.initialize!requireActiveStorage::Engine.root.join("db/migrate/20170806125915_create_active_storage_tables.rb").to_sActiveRecord::Schema.definedoCreateActiveStorageTables.new.changecreate_table:users,force: trueendclassUser < ActiveRecord::Basehas_one_attached:profileendclassBugTest < ActiveSupport::TestCasedeftest_upload_and_downloaduser=User.create!user.transactiondouser.profile.attach(content_type: "text/plain",filename: "dummy.txt",io: ::StringIO.new("dummy"))user.with_lock{}endassert_equal"dummy",user.profile.downloadendend
Expected behavior
File should be properly saved in the backend or an error raised if that is not possible.
Actual behavior
The attachment appears to work. However, when you later call #download on it, you receive an ActiveStorage::FileNotFoundError error.
If you are updating an existing attachment, the old saved file will still be deleted, but the new data will be lost.
Steps to reproduce
#transaction
or#with_lock
)#with_lock
while in the same transactionExpected behavior
File should be properly saved in the backend or an error raised if that is not possible.
Actual behavior
The attachment appears to work. However, when you later call
#download
on it, you receive anActiveStorage::FileNotFoundError
error.If you are updating an existing attachment, the old saved file will still be deleted, but the new data will be lost.
System configuration
Rails version: 7.2.1.1
Ruby version: ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
The text was updated successfully, but these errors were encountered: