Skip to content

Form.files should be a MultiValueDict #924

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

Open
rolandcrosby-check opened this issue Apr 16, 2022 · 2 comments
Open

Form.files should be a MultiValueDict #924

rolandcrosby-check opened this issue Apr 16, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@rolandcrosby-check
Copy link
Contributor

Bug report

In #909, the BaseForm class's files attribute (and everything related to it, like the files argument to Widget.value_from_datadict) were updated to _FilesT, which is defined as Mapping[str, Iterable[File]]. Unless there are counterexamples in the Django codebase that I haven't seen, I'm pretty sure this can be more specific than Mapping - it appears to be a MultiValueDict (which is what this was typed as in previous versions of django-stubs).

Is it safe to assume that this is a MultiValueDict everywhere, or can users only rely on it being a Mapping?

@rolandcrosby-check rolandcrosby-check added the bug Something isn't working label Apr 16, 2022
@sterliakov
Copy link
Contributor

(disclaimer: it was my commit)

Using Iterable was definitely a mistake, yes, it should have been Mapping[str, File].

I will revert this for now in #925 and use MultiValueDict[str, UploadedFile] for now again. I see the point that Mapping[str, Iterable[File]] is absolutely invalid (it doesn't return iterables as values) and Mapping[str, UploadedFile] doesn't work with multiple files upload (no .getlist method). However, there's problem with MultiValueDict[str, UploadedFile] too: it invalidates all test cases where we use MyForm({}, {'file_field': UploadedFile(...)}).

I think this case needs discussion and mainainer's final decision.

@sobolevn I'm sure you're one of maintainers, please resolve this or ping somebody else :)

@rolandcrosby-check
Copy link
Contributor Author

@sterliakov thanks for taking a look (and for all the great enhancements you made!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants