luolingchun / flask-openapi3

Generate REST API and OpenAPI documentation for your Flask project.
https://luolingchun.github.io/flask-openapi3/
MIT License
203 stars 33 forks source link

TypeError: FileStorage.__get_pydantic_core_schema__() takes 2 positional arguments but 3 were given #178

Closed 3raser95 closed 1 month ago

3raser95 commented 2 months ago

When using pydantic version newer than 2.8.2 I get the same error as the following user in the mentioned other issue:

I tried to run the unit tests following the CONTRIBUTING.md but they fail with errors like

E   TypeError: __get_pydantic_core_schema__() takes 2 positional arguments but 3 were given

when loading test classes like this one:

class BookForm(BaseModel):
    file: FileStorage
    files: List[FileStorage]
    string: str
    string_list: List[str]

Originally posted by @guillaume-alvarez in https://github.com/luolingchun/flask-openapi3/issues/174#issuecomment-2352201420

I also get this error with my own code and it is easily fixed by adding another argument to the function like the handler in the following FileStorage class:

@classmethod
    def __get_pydantic_core_schema__(cls, _source: Any, handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:
        return core_schema.with_info_plain_validator_function(cls.validate)