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

Confusing ephemeral behavior with has_uploadcare_file accessor #81

Closed
jackc opened this issue Feb 8, 2019 · 1 comment
Closed

Confusing ephemeral behavior with has_uploadcare_file accessor #81

jackc opened this issue Feb 8, 2019 · 1 comment

Comments

@jackc
Copy link
Contributor

jackc commented Feb 8, 2019

It appears that the accessor method generated by has_uploadcare_file creates a new Uploadcare::Rails::File instance every time it is called.

This means that calling load_data doesn't appear to have any effect unless the result is manually stored.

Given:

class Company < ApplicationRecord
  ...
  has_uploadcare_file :uploadcare_logo
  ...
end

This behavior at the console is surprising:

[23] pry(main)> company.uploadcare_logo
=> #<Uploadcare::Rails::File uuid="b170e951-xxxx-xxxx-xxxxxxxxxxxx", operations=[]>
[24] pry(main)> company.uploadcare_logo.loaded?
=> false
[25] pry(main)> company.uploadcare_logo.load_data
=> #<Uploadcare::Rails::File uuid="b170e951-xxxx-xxxx-xxxxxxxxxxxx", operations=[], ... mime_type="image/jpeg", ...>
[26] pry(main)> company.uploadcare_logo.loaded?
=> false
[27] pry(main)> a = company.uploadcare_logo
=> #<Uploadcare::Rails::File uuid="b170e951-xxxx-xxxx-xxxxxxxxxxxx", operations=[]>
[28] pry(main)> a.load_data
=> #<Uploadcare::Rails::File uuid="b170e951-xxxx-xxxx-xxxxxxxxxxxx", operations=[], ... mime_type="image/jpeg", ...>
[29] pry(main)> a.loaded?
=> true
[30] pry(main)> a.mime_type
=> "image/jpeg"
[31] pry(main)> company.uploadcare_logo.mime_type
=> nil

A quick look at the source reveals that build_file tries a lookup with Rails.cache, but it doesn't look like the file ever gets saved to the cache in the normal read case. Of course, that is beside the point of whether it makes sense for the accessor to create a new object every time, even if some of it is cached.

@dmitrijivanchenko
Copy link
Contributor

@jackc, we have released a new 2.0.0 version. We have removed caching objects behavior in v2 to cache only object attributes. Thanks for the issue 👍

❗ See migration guide, v2 is not backward compatible with v1

@rsedykh rsedykh closed this as completed Oct 13, 2021
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

3 participants