polyfactory
polyfactory copied to clipboard
Bug: PydanticFactory - `ValidationError` when using `validation_alias` on a field
Description
Originally reported here: https://github.com/litestar-org/litestar/issues/4288
When using validation_alias, a PydanticFactory will raise a ValidationError when calling .build() on the factory
URL to code causing the issue
No response
MCVE
import pydantic
from polyfactory.factories.pydantic_factory import ModelFactory
class Test(pydantic.BaseModel):
test_id: str = pydantic.Field(validation_alias="test_id_test")
class TestFactory(ModelFactory[Test]):
__model__ = Test
TestFactory.build()
Steps to reproduce
Run the code
Screenshots
"In the format of: "
Logs
Release Version
2.22.1
Platform
- [ ] Linux
- [ ] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)
I think this is hard to support as alias may be anything. I think want to push on with v3 and support this more robustly with https://github.com/litestar-org/polyfactory/issues/717