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

ImageProcessor FileDependency breaks object deletion in unit tests #33

Open
Lartza opened this issue Apr 26, 2021 · 3 comments
Open

ImageProcessor FileDependency breaks object deletion in unit tests #33

Lartza opened this issue Apr 26, 2021 · 3 comments

Comments

@Lartza
Copy link

Lartza commented Apr 26, 2021

With a very simple FileDependency model and unit test, deleting rows causes a PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\lartz\\PycharmProjects\\djangoProject\\images\\image_UQbw8fZ.jpg' error.

Minimal code and traceback:
https://gist.github.com/Lartza/84c69826b3f9eb238acf994806f6738c

EDIT: In a bigger project where I discovered this, removing images is possible from the Django Rest Framework API root

@Lartza
Copy link
Author

Lartza commented Apr 26, 2021

Closing the image field with

i = Image.objects.create(image=data)
i.image.close()

or running gc.collect() after create seems to let the following .get().delete() work correctly

@lehins
Copy link
Owner

lehins commented Apr 26, 2021

Interesting issue. Unfortunately I don't have any bandwidth to investigate it. Moreover, I haven't used this library or even python for that matter for over 5 years. @Lartza would you like to submit a PR with a fix and a test case for this, cause it doesn't look like I will get to it anytime soon?

@Lartza
Copy link
Author

Lartza commented Apr 26, 2021

It's certainly something I'm willing to investigate more when I have some time, even if I'm not sure I have the skills required to fix it.

It was suggested on IRC this would be much less likely to happen running under Linux and that requires some investigation to confirm, but for now if the issue doesn't happen in production I can likely work around it in testing and can't spend time on this for a few weeks now due to deadlines.

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

2 participants