8000 Fix #229 -- Delete old file after validation has passed by jeromelebleu · Pull Request #293 · codingjoe/django-stdimage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix #229 -- Delete old file after validation has passed #293

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
May 21, 2022

Conversation

jeromelebleu
Copy link

Note that calling file.delete(save=False) in pre_save() is not working since - if I understood correctly - it also resets the field on the model object which prevents the new file to be properly saved. Thus, we just delete the file and its variations from the storage.

@codingjoe codingjoe changed the title Delete old file when validation is passed (fix #229) Fix #229 -- Delete old file when validation has passed May 16, 2022
@codingjoe codingjoe changed the title Fix #229 -- Delete old file when validation has passed Fix #229 -- Delete old file after validation has passed May 16, 2022
@codingjoe
Copy link
Owner

Hi @jeromelebleu, thanks for the contribution. I ran the test without your patch, and it passe 8000 s. However, it should fail :( Maybe you can give it another go?

@jeromelebleu
Copy link
Author

Hi @codingjoe, so here is what I have done:

  • checkout the branch fix/229
  • revert only changes made to stdimage/models.py
  • run tests with pytest tests/test_forms.py

As expected, the test I add fails for me:

___________________________________ TestStdImageField.test_save_form_data__invalid ____________________________________
tests/test_forms.py:60: in test_save_form_data__invalid
    assert os.path.exists(org_path)
E   AssertionError: assert False
E    +  where False = <function exists at 0x7fe980c41d80>('/tmp/tmppdgy248i/img/600x400.jpg')
E    +    where <function exists at 0x7fe980c41d80> = <module 'posixpath' from '/usr/lib/python3.10/posixpath.py'>.exists
E    +      where <module 'posixpath' from '/usr/lib/python3.10/posixpath.py'> = os.path

Did you do the same?

@codingjoe
Copy link
Owner

@jeromelebleu sorry, I don't get the same error. Would you mind rebasing your commit to the latest main branch? I did start from there and then checked our your test, not the other way around.

@codecov
Copy link
codecov bot commented May 21, 2022

Codecov Report

Merging #293 (0f76c69) into master (0c5b5e5) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #293      +/-   ##
==========================================
+ Coverage   97.61%   97.67%   +0.06%     
==========================================
  Files           5        5              
  Lines         293      301       +8     
==========================================
+ Hits          286      294       +8     
  Misses          7        7              
Impacted Files Coverage Δ
stdimage/models.py 97.11% <100.00%> (+0.11%) ⬆️

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 0c5b5e5...0f76c69. Read the comment docs.

@jeromelebleu
Copy link
Author

I have rebased this branch on master, tell me if it is better…

@kciredor
Copy link

Would love to see this merged! Will there be a new release on pypi as well, with this fix included? Latest pypi is 5.3.0 whereas on github latest is 5.3.3 6.0.0 already. And while typing this I see 6.x will be receiving bugfixes only from now...

@codingjoe
Copy link
Owner

@kciredor yes, v6 will receive bug fixes, such as this one :)

@jeromelebleu, I'll give it a go.

Previously files were deleted even if the from validation failed.

Co-Authored-By: codingjoe <johannes@maron.family>
@codingjoe
Copy link
Owner

@jeromelebleu found the problem, I was missing a change in the models, that's why I didn't work for me. Now the tail fails without your patch also the patch does fix it. Furthermore, I did test the fix manually in a project. Works great!

@codingjoe codingjoe merged commit 3e473c1 into codingjoe:master May 21, 2022
@codingjoe
Copy link
Owner

@jeromelebleu maybe you'd like to contribute the file deletion feature to django-pictures as well? It hasn't been implemented it. It's the only feature missing for the beta released.

8000
@kciredor
Copy link

Thanks @jeromelebleu for the fix and @codingjoe for the pypi release with this fix!

When a future Django 5.x comes out, assuming this package would not be compatible anymore, is there a probability that the package will receive a fix release for that as well? Or should it really be considered end of life? I'm asking because out of a dozen thumbnail packages, this is the only one that seems to work properly with external storage and cleanup etc. and still being 'maintained'. For a new project I'd like to use this, but it feels a bit awkward to start a new project with a deprecated package.

@codingjoe
Copy link
Owner

@kciredor it's unlikely that we will add Django 5 support. However, django-pictures is developed by the with the same care I put into this package. It just adapted to the (new) reality of responsive web. I am sure you understand that I can only maintain so many packages at once.

All that being said, the migration to django-pictures is actually pretty straightforward. I am currently migrating a number of projects, mainly to root out some bugs. Thus far the process has been fairly easy.

@jeromelebleu
Copy link
Author

@jeromelebleu maybe you'd like to contribute the file deletion feature to django-pictures as well? It hasn't been implemented it. It's the only feature missing for the beta released.

@codingjoe I didn't give a try to django-pictures and investigate how to migrate from django-stdimage yet, and I don't have time for that at the moment unfortunately. It is in my todo list, but feel free to implement the file deletion feature if you want as it will be much faster. Thanks by the way for the release - and the work!

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.

3 participants
0