Skip to content

Fix #206 -- Overwrite variations by defaults #213

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

Merged
merged 1 commit into from
Aug 28, 2019
Merged

Conversation

codingjoe
Copy link
Owner

We now overwrite files by default when a new files gets uploaded.
This fixes an issue, where someone might upload a file with the
same name twice the first initial variations get not replaced
with a version of the newer file.
It happens in the least IO consuming way. The rendervariations
management command still behaves as before where variations are
not replaced by default.

@codingjoe
Copy link
Owner Author

@caspervk would you do me the honor of a quick review?

@codingjoe codingjoe self-assigned this Aug 6, 2019
We now overwrite files by default when a new files gets uploaded.
This fixes an issue, where someone might upload a file with the
same name twice the first initial variations get not replaced
with a version of the newer file.
It happens in the least IO consuming way. The rendervariations
management command still behaves as before where variations are
not replaced by default.
@codecov
Copy link

codecov bot commented Aug 6, 2019

Codecov Report

Merging #213 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #213   +/-   ##
=======================================
  Coverage   98.85%   98.85%           
=======================================
  Files           3        3           
  Lines          87       87           
=======================================
  Hits           86       86           
  Misses          1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba36e6c...9920fd9. Read the comment docs.

@caspervk
Copy link

caspervk commented Aug 6, 2019

@codingjoe Thank you! I only have a few comments:

  1. File is overwritten if not file_overwrite? Is this intended?
  2. Striving for as few IOs as possible, but doing both storage.exists() and storage.delete()? Is it possible to just storage.open()/.save() directly without checking if the file already exists first? I'm honestly not sure how storages work in Django, but in regular Python, doing with open("foo", "w") as f; f.write(..) will save/overwrite to foo regardless of whether the file already exists or not, achieving the desired behavior in a single IO. If storage.save() behaves in the same way, the check and deletion could possibly be refactored away?

@caspervk
Copy link

caspervk commented Aug 6, 2019

@codingjoe Actually, I just remembered that at least S3Boto3Storage from Django-storages behaves in this sane way. Simply deleting the checks and doing storage.save() (as done here) works -- no need to check and delete the file first!

@codingjoe
Copy link
Owner Author

@codingjoe Actually, I just remembered that at least S3Boto3Storage from Django-storages behaves in this sane way. Simply deleting the checks and doing storage.save() (as done here) works -- no need to check and delete the file first!

Yes, then again we do have to support more than one storage backend. Also, this is only true, if you have the overwrite-flag at its default True which many people don't. I though about just calling delete, sadly the Storage class definition does not define a common exception that should be raised. Therefore, any backend might throw a variety of different exceptions. It's not ideal, but I don't see a reliable way to improve it.

@caspervk
Copy link

I commented here: #206 (comment).

Can't wait to have this merged!

@codingjoe codingjoe merged commit 7efcd28 into master Aug 28, 2019
@codingjoe codingjoe deleted the issues/206 branch August 28, 2019 12:31
@codingjoe
Copy link
Owner Author

Released in 5.0.1

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 this pull request may close these issues.

2 participants