Skip to content

Inconsistency between HttpRequest and parse_file_upload method introduced in 5.2.1 #2717

@g-as

Description

@g-as

Bug report

What's wrong

#2654 removed BytesIO inheritance from HttpRequest which clashes with parse_file_upload signature.

    def parse_file_upload(
        self, META: Mapping[str, Any], post_data: BinaryIO
    )

A HttpRequest instance used to be allowed as a post_data value. But not anymore:

error: Argument 2 to "parse_file_upload" of "HttpRequest" has incompatible type "HttpRequest"; expected "BinaryIO"  [arg-type]

How is that should be

A HttpRequest instance should be a legitimate post_data value, as seen in HttpRequest._load_and_post_files method:

            if hasattr(self, "_body"):
                # Use already read data
                data = BytesIO(self._body)
            else:
                data = self
            try:
                self._post, self._files = self.parse_file_upload(self.META, data)
            except (MultiPartParserError, TooManyFilesSent):
                ...

System information

  • OS: debian
  • python 3.12
  • django 5.2
  • mypy 1.16.1
  • django-stubs 5.2.1
  • django-stubs-ext 5.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions