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

fix: file validators were editing the file fields content #578

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

azmeuk
Copy link
Member

@azmeuk azmeuk commented Oct 1, 2023

When I was playing with the last flask-wtf I noticed that the file validators were editing the field.data since #556, leading to incompatibilities: on simple FileField my code was expecting a simple FileStorage and not a list of FileStorage. However the if not isinstance(field.data, list): field.data = [field.data] lines was setting a list even for simple FileField

@greyli what do you think?

@azmeuk azmeuk added the bug label Oct 1, 2023
@azmeuk azmeuk requested a review from greyli October 1, 2023 14:14
@zorun
Copy link

zorun commented Oct 1, 2023

FYI, we are also seeing failures in Ihatemoney. Here is an example code that now fails with flask-wtf 1.2.0, the form has a single FileField called file:

        form = ImportProjectForm()
        if form.validate():
            try:
                data = form.file.data
>               if data.mimetype == "application/json":
E               AttributeError: 'list' object has no attribute 'mimetype'

@guidoiaquinti
Copy link

guidoiaquinti commented Oct 2, 2023

Same issue here with a form with a simple FileField. On 1.2.0 is breaking with:

{"event": "ParamValidationError(\"Parameter validation failed:\\nInvalid type for parameter Body, value: [<FileStorage: 'passport.jpg' ('image/jpeg')>], type: <class 'list'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object\")", "timestamp": "2023-10-02T06:12:56.024783Z", "thread": 281472627896800, "user_id": "qa7n0w6vku6ksld"}

@azmeuk azmeuk merged commit 6804696 into pallets-eco:main Oct 2, 2023
6 checks passed
@azmeuk azmeuk deleted the pr-558-fix branch October 2, 2023 07:46
@azmeuk
Copy link
Member Author

azmeuk commented Oct 2, 2023

The fix is in v1.2.1

@greyli
Copy link
Member

greyli commented Oct 11, 2023

@azmeuk Thanks for the quick fix! Sorry, I was on holiday last week.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

4 participants