Skip to content

Conversation

@borisowww
Copy link

@borisowww borisowww commented Jul 13, 2023

Description

When trying to validate a File parameter in flask, I get an error TypeError: __init__() got an unexpected keyword argument 'min_length'.

Basic setup

@app.route('/route', methods=["POST"])
@ValidateParameters()
def method(
        image: Any = File(),
        height: str = Form()
):
    return "Success", 200

Fix

My fix basically provides the min_length and max_length arguments to the File class, so they can be used in the validate method.

Additionally, the correct type for Files should be werkzeug.datastructures.FileStorage, otherwise some validations don't get triggered, due to

        # Skip validation if typing.Any is given
        if expected_input_type_str.startswith("typing.Any"):
            return user_input

so I updated the README with the suggested file type.

@borisowww borisowww force-pushed the fix-file-validation branch from a3d5061 to e869a19 Compare July 13, 2023 16:42
@borisowww borisowww force-pushed the fix-file-validation branch from e869a19 to 16b207a Compare July 13, 2023 17:10
@Ge0rg3 Ge0rg3 merged commit 725e80b into Ge0rg3:master Sep 5, 2023
@Ge0rg3
Copy link
Owner

Ge0rg3 commented Sep 5, 2023

Thanks @borisowww, nicely spotted, much appreciated 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants