In a Pydantic model, when using Config
field min_anystr_length
(to set a minimum length for all strings in the model), Polyfactory does not seem to take it into account which leads to pydantic validation errors during build.
My understanding is that currently, Polyfactory only parses the allow_population_by_field_name
(here) from the Config
.
Is this assessment correct ? Thank you for your help !
No response
from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import BaseModel
ModelFactory.seed_random(0)
class TestClass(BaseModel):
class Config:
min_anystr_length = 100
myfield: str
class TestClassFactory(ModelFactory[TestClass]):
__model__ = TestClass
class TestClassWithoutConfig(BaseModel):
myfield: str
class TestClassWithoutConfigFactory(ModelFactory[TestClassWithoutConfig]):
__model__ = TestClassWithoutConfig
print(TestClassWithoutConfigFactory.build()) # OK
print(TestClassFactory.build()) # ERROR
#E pydantic.error_wrappers.ValidationError: 1 validation error for TestClass
#E myfield
#E ensure this value has at least 100 characters (type=value_error.any_str.min_length; #limit_value=100)
Execute the example above (pydantic 1.10)
No response
E pydantic.error_wrappers.ValidationError: 1 validation error for TestClass
E myfield
E ensure this value has at least 100 characters (type=value_error.any_str.min_length; limit_value=100)
2.12.0
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too