-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Filenames Prefixed With Long String of Numbers After Upgrade to 3.0.7 #2736
Comments
This can be related to 4c65b39, but I couldn't reproduce the issue using this single-file snippet: # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails"
gem "sqlite3"
# gem "carrierwave", "3.0.5"
gem "carrierwave", "3.0.7"
end
require "rails/all"
require 'logger'
Rails.logger = Logger.new(STDOUT)
class App < ::Rails::Application
end
require "carrierwave"
require "carrierwave/orm/activerecord"
require "minitest/autorun"
CarrierWave.root = File.expand_path(".")
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(File::NULL)
ActiveRecord::Schema.define do
create_table :attachments, force: true do |t|
t.string :file_name
end
end
class AttachmentUploader < CarrierWave::Uploader::Base
include Rails.application.routes.url_helpers
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_allowlist
%w(pdf png jpeg jpg tiff tif)
end
end
class Attachment < ActiveRecord::Base
mount_uploader :attachment_file, AttachmentUploader, mount_on: :file_name
end
class Test < Minitest::Test
def test_reload
pdf_file = File.new("#{Dir.tmpdir}/test.pdf", "wb")
pdf_file.write("test")
a = Attachment.new(attachment_file: pdf_file)
a.save!
puts "Original File Path - #{pdf_file.path}"
puts "After Save - #{a.attachment_file}"
a.reload
puts "After Reload - #{a.attachment_file}"
end
end
Can you try to reproduce by using this? |
Same result. Magic generation ID prepended using version 3.0.7
|
OK could you paste the full output? Here's my result:
|
We hit the same issue and tracked it down to version 3.0.6, but could not come up with a reproducible example yet. There is one thing that may indicate an issue:
and the result
|
Running your supplied snippet produced the same results as yours. I provided an example of the behavior that I found from one of my unit tests that suddenly went red when I attempted to move from 3.0.5 to 3.0.7. I appreciate the need to reproduce the error to fix it but I am at a loss as what extra information is needed. |
This is definitely related to 4c65b393. Hated to do it, but it is monkey patch time. Added an initializer with this...
And my tests have returned to green. |
Only 2 of you having the issue suggests you have non-standard implementation in your app. |
So much for a minor update....
Simple method for attaching a PDF to an active record object (puts statements for debugging)
Output 3.0.7
Original File Path - /var/folders/jt/rm2yhr0n72n3strzh46jxsr80000gp/T/Claim_Summary_Smith_Paula.pdf
After Save - /uploads/attachment/attachment_file/1010673124/Claim_Summary_Smith_Paula.pdf
After Reload - /uploads/attachment/attachment_file/1010673124/1712335404-594640814208633-0001-0461/ Claim_Summary_Smith_Paula.pdf
Where did 1712335404-594640814208633-0001-0461/ come from? How can I stop it?
This what used to happen, and what I expected to continue to happen...
Output 3.0.5
Original File Path - /var/folders/jt/rm2yhr0n72n3strzh46jxsr80000gp/T/Claim_Summary_Smith_Paula.pdf
After Save - /uploads/attachment/attachment_file/1010673124/Claim_Summary_Smith_Paula.pdf
After Reload - /uploads/attachment/attachment_file/1010673124/Claim_Summary_Smith_Paula.pdf
The uploader mount on the Attachment object...
mount_uploader :attachment_file, AttachmentUploader, mount_on: :file_name
The uploader...
Curious where the prefix folder 1712335404-594640814208633-0001-0461/ came from in the file name and how it can be prevented.
Note the reload was added to the method to demonstrate the problem. Issue manifests itself when attempting to access the file after it was attached.
Rails 6.1.7.7
Ruby 3.2.2
The text was updated successfully, but these errors were encountered: