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

Bug: Validation Error in Pydantic model with optional list #559

Open
1 of 4 tasks
RLC92 opened this issue Jun 26, 2024 · 1 comment
Open
1 of 4 tasks

Bug: Validation Error in Pydantic model with optional list #559

RLC92 opened this issue Jun 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@RLC92
Copy link

RLC92 commented Jun 26, 2024

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

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

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@RLC92 RLC92 added the bug Something isn't working label Jun 26, 2024
@RLC92
Copy link
Author

RLC92 commented Jun 26, 2024

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.

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

No branches or pull requests

1 participant