-
-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
Regex seems to be ignored inside dicts, as Polyfactory is generating `` as a value:
{'environment_variables': {'XZdrHqToIHlKKDxepfKJ': ''}}
Calling build()
10 times results in None
6 times, and `` 4 times.
--
This does NOT happen when the value is not nullable, i.e.:
class Model(BaseModel):
environment_variables: Dict[str, constr(regex=r"^[A-Za-z_]+$")]
--
This ALSO happens when key/value are swapped:
class Model(BaseModel):
environment_variables: Optional[Dict[constr(regex=r"^[A-Za-z_]+$"), str]]
Result:
{'environment_variables': {'': 'BildVEhMalDZKoEqvGvl'}}
--
This does NOT happen outside a dict:
class Model(BaseModel):
environment_variables: constr(regex=r"^[A-Za-z_]+$")
Result:
{'environment_variables': 'XCjdsB'}
URL to code causing the issue
No response
MCVE
from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import BaseModel
from typing import Optional,Dict
from pydantic import constr,Field
class Model(BaseModel):
environment_variables: Optional[Dict[str, constr(regex=r"^[A-Za-z_]+$")]]
class Factory(ModelFactory[Model]):
...
print(Factory.build())
Steps to reproduce
See MRE
Screenshots
No response
Logs
Release Version
2.21.0
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working