-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Version Caching Fails with CarrierWave::InvalidParameter: invalid cache id on Stored Files #2798
Description
Hello CarrierWave Maintainers,
During migration from CarrierWave 2.2.6 to 3.x, we encountered an issue where versioned files stored in the backend are no longer cached for subsequent processing as they were in previous versions.
The problem appears to be caused by the fix for #2480, which was likely triggered by a non-deterministic filename method in user code rather than a core gem logic issue.
In CarrierWave::Uploader::Versions::Builder#cache!, the gem attempts to copy the parent uploader’s cache_id:
def cache!(*args)
self.cache_id = parent_version.cache_id if parent_version
super
end
However, when uploading a versioned file from the store, parent_version is nil during caching. This breaks caching of versioned files and prevents downstream processing, such as merging PDF files or other transformations, often resulting in:
CarrierWave::InvalidParameter: invalid cache id
It looks like these issues are also related to this error. first second
Environment:
CarrierWave 2.2.6 → .3.1.2
Ruby 3.3.7
rails '7.2.2.2'
Storage: cache llocall, store S3
❌ Actual Behavior
Calling any method that triggers the cache process on a stored version fails immediately:
Ruby
@uploader_instance.version_name.cache_stored_file!
# => CarrierWave::InvalidParameter Exception: invalid cache id
✅ Expected Behavior
The version file should be downloaded from permanent storage into the temporary cache directory, allowing further processing steps (like PDF conversions or custom manipulation) to be executed on the local file path.
Thank you for looking into this regression. We appreciate your efforts in maintaining security while preserving necessary application functionality.