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

Different behaviour for mount_on with blank values between 1.3.1 and 2.1.0 #2511

Open
schinery opened this issue Sep 24, 2020 · 0 comments
Open

Comments

@schinery
Copy link
Contributor

I've just been upgrading some projects that use Carrierwave, and have stumbled upon a change in behaviour that is causing me some problems, and I want to check if I've missed something as part of the upgrade.

This is the existing DB schema which was created pre 1.3.1:

create_table "things", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t|
  t.text "filenames", default: [], array: true
end

This is the existing model that has the mount_uploaders added to it:

class Thing < ApplicationRecord
  mount_uploaders :files, FilesUploader, mount_on: :filenames
end

In Carrierwave 1.3.1 if I was to find a Thing object with no filenames currently set it would return a blank array on the object.

thing = Thing.find("92773c7b-6341-411e-980b-4073531f5c53")
#<Thing id: "92773c7b-6341-411e-980b-4073531f5c53", filenames: []>

In 2.1.0 though, it returns filenames as nil.

thing = Thing.find("92773c7b-6341-411e-980b-4073531f5c53")
#<Thing id: "92773c7b-6341-411e-980b-4073531f5c53", filenames: nil>

This is causing me problems where I had existing code that was doing something like thing.filenames + params[:filenames] because it is now trying to use + on nil. I know I can cast using Array(thing.filenames) but wanted to see if there was reason for this change or whether I need to do something else in my code?

@schinery schinery changed the title Different behaviour for mount_uploaders mount_on blank values between 1.3.1 and 2.1.0 Different behaviour for mount_on with blank values between 1.3.1 and 2.1.0 Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant