django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

request.FILES should respect settings.FILE_UPLOAD_HANDLERS

Open daneah opened this issue 3 years ago • 0 comments

Bug report

What's wrong

Currently, trying to use an attribute of a file from request.FILES that I know exists because I've set settings.FILE_UPLOAD_HANDLERS explicitly still results in a type checking error like the following:

views.py:135: error: "UploadedFile" has no attribute "temporary_file_path"

How is that should be

If you've set settings.FILE_UPLOAD_HANDLERS explicitly (either always forcing in-memory files or temporary uploaded files, or having your own custom handler class), then request.FILES should be expected to be a list of the type returned by the upload handler.

This can be worked around by adding something like the following before using the attribute:

assert type(the_file) is TemporaryUploadedFile

System information

  • OS: macOS
  • python version: 3.10
  • django version: 4.0.1
  • mypy version: 0.961
  • django-stubs version: 1.12.0
  • django-stubs-ext version: N/A

daneah avatar Jul 02 '22 17:07 daneah