#36761 closed Cleanup/optimization (invalid)

Closed file handles in test URL patterns for FileResponse

Reported by: Mohit Sharma Owned by:
Component: Testing framework Version: dev
Severity: Normal Keywords: file-handle resource-cleanup testing
Cc: Mohit Sharma Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Change History (1)

comment:1 by Simon Charette, 12 minutes ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top