litestar-org/polyfactory

Bug: Optional lists in coverage produce nested lists

Opened this issue · 2 comments

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

  • 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

@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

Seems to be same as: #559

Sorry for the duplicate.