Closed krasnoukhov closed 1 year ago
I tried this in our app and it does not seem to be a solution since we rely on model.id
for filename so store must happen after save...
Ok I guess there's no way to call deduplicate at the other time. We need to call it at the store point because this is when everything is ready to check for duplication. But yes, deduplication can result in dirty value which needs to be persisted. So I've added a persistence mechanism and AR integration. Let me know your thoughts.
You're totally right, I'm really sorry that one of key features in the release 3.0 is completely broken.
But the #persist_uploader
idea doesn't seem to be ideal, as it will incur an additional RDB access. Let me try to think about other solutions.
Closing in favor of #2679
I noticed an issue that when using ActiveRecord and trying to update the mounted file with a different file of the same name it is deduplicated logically but that change is not persisted, resulting in
current_path
orurl
pointing to the "old" filename which does not exist (cause it was deleted). So deduplication works but it's not persisted. There was a spec for this case but in spec record was not reloaded (dirty) so it passed. Spec failure before code changes:Changing to
before_save
makeswrite_identifier
also kick in before record is persisted which makes issue go away. Not sure ifbefore_save
can have other complications, but it seems like it's working... The alternative would be to move thisdeduplicate
call to happen before save:https://github.com/carrierwaveuploader/carrierwave/blob/478eccc3cdf955406266f57027fb367f47b64c38/lib/carrierwave/mounter.rb#L145
Another alternative would be to perform another save after store.