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

ActiveRecord model keeps dirty after update #2702

Closed
ssugiyama opened this issue Sep 11, 2023 · 3 comments · Fixed by #2707
Closed

ActiveRecord model keeps dirty after update #2702

ssugiyama opened this issue Sep 11, 2023 · 3 comments · Fixed by #2707

Comments

@ssugiyama
Copy link

class FooUploader < CarrierWave::Uploader::Base
  def filename
    'a.png'
  end
end
class Foo < ApplicationRecord
  mount_uploader :image, FooUploader
end
foo = Foo.create!(...)
foo.update!(image: File.open(...))
puts foo.changed? # expecting 'false' but we get 'true'

this problem occurs since 3.0.0.rc to 3.0.3
only if filename method is defined in uploader
and saved outside transactions (if saved inside transactions, we get 'false')

Are there any workarounds or required settings?

@rajyan
Copy link
Contributor

rajyan commented Sep 11, 2023

Is this issue related to your problem?
#2682

@ssugiyama
Copy link
Author

ssugiyama commented Sep 13, 2023

Is this issue related to your problem?

Maybe, not. We tried changing filename in every save, but the problem was reproduced.

class FooUploader < CarrierWave::Uploader::Base
  def filename
    (Time.now.to_f * 1000).to_s + '.png'
  end
end

Here is additional information.

foo = Foo.create!(image: File.open('oldfile.png'))
foo.update!(image: File.open('newfile.png'))
puts foo.changes
=> {"image"=>["1694578531581.793.png", "newfile.png"]}

rajyan added a commit to rajyan/carrierwave that referenced this issue Sep 13, 2023
rajyan added a commit to rajyan/carrierwave that referenced this issue Sep 13, 2023
@rajyan
Copy link
Contributor

rajyan commented Sep 13, 2023

Thank you for the detailed information!
I think #2707 fixes this bug.

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

Successfully merging a pull request may close this issue.

2 participants