#36761: Closed file handles in test URL patterns for FileResponse
-------------------------------------+-------------------------------------
Reporter: Mohit Sharma | Type:
| Cleanup/optimization
Status: new | Component: Testing
| framework
Version: dev | Severity: Normal
Keywords: file-handle | Triage Stage:
resource-cleanup testing | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
== Problem ==
Test URL patterns in `tests/wsgi/urls.py` and `tests/asgi/urls.py` use
lambda functions to open files for FileResponse without proper resource
management.
== Location ==
- `tests/wsgi/urls.py:18`
- `tests/asgi/urls.py:71`
== Current Code ==
path("file/", lambda x: FileResponse(open(__file__, "rb"))),== Solution ==
Convert lambda functions to proper view functions to ensure better
resource management and code clarity. FileResponse will still handle
closing the file when the response is closed, but using proper view
functions is cleaner and more maintainable.
== Patch ==
I have a patch ready that converts the lambda functions to proper view
functions.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36761>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.