litestar-org / polyfactory

Simple and powerful factories for mock data generation
https://polyfactory.litestar.dev/
MIT License
988 stars 78 forks source link

Bug: Optional lists in coverage produce nested lists #526

Closed Vegemash closed 1 month ago

Vegemash commented 4 months ago

Description

A pydantic BaseModel field with the type list[int] | None will produce [[123]]

Fix incoming

MCVE

from pydantic import BaseModel
from polyfactory.factories.pydantic_factory import ModelFactory

class Model(BaseModel):
   optional_list: list[int] | None

list(ModelFactory._get_or_create_factory(Model).coverage())

Steps to reproduce

Run the above

Release Version

2.15

Platform


[!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

guacs commented 4 months ago

@Vegemash thanks for reporting this and for the PR! I'm a bit swamped at the moment, but I'll take a look at the PR (if no one else has a chance) sometime this week.

RLC92 commented 2 months ago

Seems to be same as: https://github.com/litestar-org/polyfactory/issues/559

Sorry for the duplicate.