Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #17235 -- Made MultiPartParser leave request.FILES immutable. #17991

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bcail
Copy link
Contributor

@bcail bcail commented Mar 18, 2024

Trac ticket number

ticket-17235

Branch description

Made request.FILES immutable. Continued the work from PR #10110 by @vinayinvicible.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • For UI changes, I have attached screenshots in both light and dark modes.

Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @bcail ⭐ I have initial comments

@@ -361,7 +361,7 @@ def _parse(self):
# Signal that the upload has completed.
# any() shortcircuits if a handler's upload_complete() returns a value.
any(handler.upload_complete() for handler in handlers)
self._post._mutable = False
self._post._mutable = self._files._mutable = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._post._mutable = self._files._mutable = False
self._post._mutable = False
self._files._mutable = False

I find this easier to read

@@ -69,8 +69,11 @@ class MultiValueDict(dict):
single name-value pairs.
"""

def __init__(self, key_to_list_mapping=()):
_mutable = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_mutable = True
# This is reset in __init__, but is specified here at the class level so
# that unpickling will have valid values
_mutable = True

Think maybe we should have the same comment as QueryDict here

def __init__(self, key_to_list_mapping=()):
_mutable = True

def __init__(self, key_to_list_mapping=(), mutable=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In QueryDict we have mutable=False as the default, have you had a look as to whether that would make sense here?

Comment on lines +185 to +195
def pop(self, key, *args):
self._assert_mutable()
return super().pop(key, *args)

def popitem(self):
self._assert_mutable()
return super().popitem()

def clear(self):
self._assert_mutable()
super().clear()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As QueryDict inherits MultiValueDict, you might be able to remove/refactor some of the code there.
Might be more than just these

@smithdc1
Copy link
Member

I wonder about backward compatability here. It's been this way forever so, while it's not recommended, I'm sure someone will be relying on it being mutable.

One suggestion would be to add this change in behaviour as part of the new content type parsing (#17546). The next step there is for someone to write a DEP so this behaviour change could form part of that.

@sarahboyce
Copy link
Contributor

I wonder about backward compatability here. It's been this way forever so, while it's not recommended, I'm sure someone will be relying on it being mutable.

Oh you make a good point 🤔
I guess this needs a release note at the very least

One suggestion would be to add this change in behaviour as part of the new content type parsing (#17546). The next step there is for someone to write a DEP so this behaviour change could form part of that.

@bcail what do you think? Being part of the push for #17546 would be amazing. I really appreciate the work you've been doing and I think having a look at this and the DEP process could be a valuable experience if you're up for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants