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

ResourceWarning: unclosed file in create_thumbnail #244

Open
cbporch opened this issue Jan 4, 2024 · 0 comments
Open

ResourceWarning: unclosed file in create_thumbnail #244

cbporch opened this issue Jan 4, 2024 · 0 comments

Comments

@cbporch
Copy link

cbporch commented Jan 4, 2024

The File orig and ContentFile thumb_file variables created in Avatar.create_thumbnail do not appear to be closed before the method returns: https://github.com/jazzband/django-avatar/blob/main/avatar/models.py#L142

Django: 4.1.13
django-avatar: 8.0.0
Python 3.10

While upgrading Django, I noted the following error while running pytest with -Wa flags enabled & PYTHONWARNINGS=always in my env:

/usr/local/lib/python3.10/dist-packages/avatar/models.py:201: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/tmphkurztys/img/avatar/1/29711aa648bad2dca40e2463dc8761cb.gif'>
  instance.create_thumbnail(size, size)
Enable tracemalloc to get traceback where the object was allocated.
See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

Hopping into a debugger, I can see that by the bottom of the function both have a closed property of False:
Screenshot 2024-01-04 at 1 57 05 PM
Screenshot 2024-01-04 at 1 57 10 PM

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

1 participant