[Django] #36761: Closed file handles in test URL patterns for FileResponse

3 views
Skip to first unread message

Django

unread,
Dec 1, 2025, 8:37:53 PM (2 days ago) Dec 1
to django-...@googlegroups.com
#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.

Django

unread,
Dec 1, 2025, 9:03:51 PM (2 days ago) Dec 1
to django-...@googlegroups.com
#36761: Closed file handles in test URL patterns for FileResponse
-------------------------------------+-------------------------------------
Reporter: Mohit Sharma | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Testing framework | Version: dev
Severity: Normal | Resolution: invalid
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
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* resolution: => invalid
* status: new => closed

Comment:

As far as I know the usage of functions over lambdas do not ''ensure
better resource management'' and it's not something you've provided
supporting evidence for.

If it was the case and we were dealing with a resource management problem
when running test we might want to consider replacing the usage of lambdas
where it makes sense but we certaintly don't want to change some instances
and not others as it's a slippery slope for noisy contributions.
--
Ticket URL: <https://code.djangoproject.com/ticket/36761#comment:1>
Reply all
Reply to author
Forward
0 new messages