litestar-org / polyfactory

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

fix: handle unions properly #491

Closed guacs closed 9 months ago

guacs commented 9 months ago

Description

This is a rewrite of #412, but it fixes the issues that was there with pydantic v1.

Quoting from the above mentioned PR:

This PR fixes the handling of unions. The use of unwrap_args would result in the incorrect creation of children for the field meta. It would just return a random instance of the union and it fails completely in the case of unions of collection types like list[int] | list[str] where unwrap_args might return (int,) for type_args when in fact we want (list[int], list[str]).

Close Issue(s)

sonarcloud[bot] commented 9 months ago

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
78.3% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

github-actions[bot] commented 9 months ago

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/491