Even the simplest model with an optional list appears to not work. Instead of generating a valid coverage including None and a random string, a validation error is raised. Worth noting that it seems to be making a list of list of str, rather than a list of string.
from pydantic import BaseModel
from typing import Optional, List, Union # Note: Optional is included as I tried it as well, realize that it is also just a union.
from polyfactory.factories.pydantic_factory import ModelFactory
class ExampleModel(BaseModel):
values: Union[List[str], None]
class ExampleModelFactory(ModelFactory):
__model__ = ExampleModel
if __name__ == "__main__":
print(list(ExampleModelFactory.coverage()))
Steps to reproduce
1. Install dependencies (I'm using 1.10.17 and polyfactory 2.16.0)
2. Run the example.
3. Get a validation failure in coverage:
pydantic.error_wrappers.ValidationError: 1 validation error for ExampleModel
values -> 0
str type expected (type=type_error.str)
Screenshots
No response
Logs
No response
Release Version
2.16.0
Platform
[X] Linux
[ ] Mac
[ ] Windows
[ ] Other (Please specify in the description above)
Also sorry if the post was a little dorked, I tried to edit it to make it right but I don't report on Github very frequently, hopefully this'll improve with practice.
Description
Even the simplest model with an optional list appears to not work. Instead of generating a valid coverage including
None
and a random string, a validation error is raised. Worth noting that it seems to be making a list of list of str, rather than a list of string.URL to code causing the issue
https://github.com/RLC92/polyfactory_error_submission
MCVE
Steps to reproduce
Screenshots
No response
Logs
No response
Release Version
2.16.0
Platform