-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Variants are not re-generated on overwrite image #206
Comments
Hi @MingTheGit thanks for your kind words and thanks for reaching out. I let me try to rephrase your situation, to make sure I am getting it right. You are uploading a new file, with the same name as a previously uploaded file, right? You are not using the That being said, if the setting is set to I hope that helps you a bit, let me know if you have any further questions. Best |
@codingjoe Thanks for your quick answer!
Did you mean "That being said, if the setting is set to
I'm not using management command, posting snippet of my code.
|
@MingTheGit check these lines here: django-stdimage/stdimage/models.py Lines 62 to 69 in 920c68b
You see, we check if the file already exists. The default behavior is not to override existing files. In any case, your filename pattern would require you to actually delete the picture before overriding it. That being said, i don't know if this is a good filename pattern. It depends on your bucket policy is set to private, otherwise guessing filenames is pretty easy. Check out another creation of mine, to create more advanced filename patterns: https://github.com/codingjoe/django-dynamic-filenames |
Thanks for your checking, I appreciate it. I have tried some debugging and it seems like this is going to be a new feature request. So, replace flag is always False in my case, because I'm not using management command. django-stdimage/stdimage/models.py Lines 52 to 58 in 920c68b
Can you please consider adding |
How it works in the following scenarios
replace flag is not checked at all, because |
@MingTheGit I didn't plan on implementing that feature, but feel free to make a suggestion. |
Why is this issue closed? It can never be correct behavior to replace the original while preserving the old variations, resulting in completely different images depending on the variation. Either all variations (including the original) should be replaced or none of them should. |
@caspervk: If you believe this to be a bug, I can't wait for your PR to resolve it :) |
Ideally, I would remove the following check from the Index: stdimage/models.py
===================================================================
--- stdimage/models.py (revision 29f5e6a00cbb5353917f2adbd8f93bcb6e9461d9)
+++ stdimage/models.py (date 1563267502420)
@@ -58,15 +58,6 @@
storage=default_storage):
"""Render an image variation and saves it to the storage."""
variation_name = cls.get_variation_name(file_name, variation['name'])
- if storage.exists(variation_name):
- if replace:
- storage.delete(variation_name)
- logger.info('File "%s" already exists and has been replaced.',
- variation_name)
- else:
- logger.info('File "%s" already exists.', variation_name)
- return variation_name
-
ImageFile.LOAD_TRUNCATED_IMAGES = True
with storage.open(file_name) as f:
with Image.open(f) as img: As @MingTheGit said, it the job of |
@MingTheGit as much as I agree with the problem, I would caution you a bit regarding the solution. Please keep in mind, that changing the behavior should not be done quietly. Currently, existing variations are not overridden. So if we are to change the behavior, we need to do it in a way, that informs users should the update. |
@codingjoe I absolutely agree that care must be taken not to introduce changes that cause data-loss for existing users. How about a new major release, as has been done in the past? |
@caspervk a major release is not a problem, but preferable even then, the API changes if the behavior changes, so that users need to adapt their implementation. The problem is, that not everyone reads release notes :/ |
@codingjoe Given the fact that the original is overwritten while the variations are not, I just cannot see anyone using this bug as feature, as it would leave their system in an inconsistent state. In my opinion, an option is not the way to go, as it really should be the default to overwrite, like I've tried to argue for in this thread previously. The point about API and behavioral changes is a good one, but I'm not sure how this bug can be fixed then. One solution could be to release a new minor version with a check that emits a loud warning if an image would be overwritten using the new logic, and then release a new major version that actually overwrites some time later. |
You make a good point @caspervk. To be fair though, I am not aware of any storage backend – except S3 – that overrides files by default. This is strange behavior and I presume it only exists, because the none-overwrite implementation does need to make an extra call and increases IO. I will propose a patch. Let's see if this would solve your problem. |
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.
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.
Appending a hash to the filename instead of overwriting is not normal behavior for any filesystem -- it is very much expected that files will be overwritten by default. At least in regular Python, doing with I am, however, not sure how storage backends work in Django - maybe it is normal behavior not to overwrite? Regardless, I think you should fix this issue in the best way you see fit - you are the expert on the inner workings of this library after all 😄 |
Thanks for putting efforts into this great package! I found this one most relevant to my requirement, among several django imaging libraries.
The only issue I'm having is variants don't get regenerated when you replace an existing image.
It works fine locally (
django.core.files.storage.FileSystemStorage
), but not on S3 (storages.backends.s3boto3.S3Boto3Storage
). Only main image is replaced, and thumbnail variants remain untouched.main_image.png
(replaced with new one)main_image.md.png
(untouched, old)main_image.sm.png
(untouched, old)My workaround was to add random hash to file name so that set of 3 new images are created on S3 bucket, each time you replace. It's not good enough since old images hold the space.
It would be great if someone can take a quick double check, and fix if easy.
The text was updated successfully, but these errors were encountered: