Opened 6 weeks ago

Closed 7 days ago

#36841 closed New feature (fixed)

Add multipart_parser_class attribute to HttpRequest for pluggable multipart parsing

Reported by: Farhan Ali Owned by: Farhan Ali
Component: HTTP handling Version: dev
Severity: Normal Keywords: mutipart-parsing
Cc: Farhan Ali Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Problem

Django's parse_file_upload() hardcodes MultiPartParser, making it hard
to swap in faster implementations.

Proposed Solution

As discussed with the steering council and Carlton Gibson on the forum:

  1. Add multipart_parser_class class attribute to HttpRequest (defaulting to MultiPartParser)
  1. Modify parse_file_upload() to use self.multipart_parser_class instead of direct import
  1. Ensure uniform parser interface: __init__(META, input_data, upload_handlers, encoding) with parse() returning (POST, FILES)

Usage

Users can subclass HttpRequest and override multipart_parser_class to use
faster parsers.

Benefits

  • Immediate performance improvements for those who need them
  • Stepping stone toward DEP 17 https://github.com/django/deps/pull/88 (pluggable content type parsers)
  • Minimal change
  • Follows proven pattern from Django REST Framework's parser_classes

Forum Discussion

https://github.com/django/new-features/issues/105

Change History (12)

comment:1 by Farhan Ali, 6 weeks ago

Owner: set to Farhan Ali

comment:2 by Natalia Bidart, 6 weeks ago

Triage Stage: UnreviewedAccepted

Thanks for opening the ticket and for following the prior discussion!

The DRF comparison is useful as prior art, but this does not add view-level parser_classes, keeping the scope intentionally small. Configurability via a custom HttpRequest subclass is sufficient at this stage and keeps the change minimal.

Proceeding with a PR along these lines sounds good, looking forward to that!

comment:3 by Farhan Ali, 6 weeks ago

Has patch: set

comment:4 by Farhan Ali, 6 weeks ago

Opened a PR https://github.com/django/django/pull/20498. But it will need a guide in the docs, I think how to use this feature properly.

comment:5 by Jacob Walls, 6 weeks ago

Needs documentation: set

comment:6 by Farhan Ali, 6 weeks ago

Needs documentation: unset

comment:7 by Jacob Walls, 3 weeks ago

Patch needs improvement: set

Don't want to increase scope here, but just left one question to ensure we protect the smoothest possible adoption path for the pending content-type DEP.

comment:8 by Jacob Walls, 3 weeks ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

I think this is ready. I'll leave it RFC for a week or two given that I just pinged a couple folks, but I won't let it die on the vine.

comment:9 by Jacob Walls, 13 days ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Still on the verge of merge, one tweak needed on the exception class.

comment:10 by Farhan Ali, 12 days ago

Patch needs improvement: unset

comment:11 by Jacob Walls, 12 days ago

Triage Stage: AcceptedReady for checkin

comment:12 by Jacob Walls <jacobtylerwalls@…>, 7 days ago

Resolution: fixed
Status: assignedclosed

In 7732f94:

Fixed #36841 -- Made multipart parser class pluggable on HttpRequest.

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