In polyfactory 2.13.0, a boilerplate factory for this model worked fine. However, with the upgrade to 2.14.0, we started seeing the exception in the title.
URL to code causing the issue
No response
MCVE
from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import (
BaseModel,
Field,
StrictFloat,
StrictInt,
)
class Config(BaseModel):
property: StrictInt | StrictFloat = Field(le=1000000)
class ConfigFactory(ModelFactory[Config]):
...
if __name__ == "__main__":
ConfigFactory.build()
Steps to reproduce
1. Install packages pydantic~=2.5.3 and polyfactory==2.14.0
2. Execute the file with python
3. See error
Screenshots
No response
Logs
Traceback (most recent call last):
File "/Users/berkaycagir/test.py", line 19, in <module>
ConfigFactory.build()
File "/Users/berkaycagir/.pyenv/versions/test-env/lib/python3.12/site-packages/polyfactory/factories/pydantic_factory.py", line 385, in build
processed_kwargs = cls.process_kwargs(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/berkaycagir/.pyenv/versions/test-env/lib/python3.12/site-packages/polyfactory/factories/base.py", line 955, in process_kwargs
field_result = cls.get_field_value(
^^^^^^^^^^^^^^^^^^^^
File "/Users/berkaycagir/.pyenv/versions/test-env/lib/python3.12/site-packages/polyfactory/factories/base.py", line 694, in get_field_value
return cls.get_constrained_field_value(annotation=unwrapped_annotation, field_meta=field_meta)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/berkaycagir/.pyenv/versions/test-env/lib/python3.12/site-packages/polyfactory/factories/pydantic_factory.py", line 368, in get_constrained_field_value
return super().get_constrained_field_value(annotation, field_meta)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/berkaycagir/.pyenv/versions/test-env/lib/python3.12/site-packages/polyfactory/factories/base.py", line 660, in get_constrained_field_value
raise ParameterException(msg)
polyfactory.exceptions.ParameterException: received constraints for unsupported type typing.Union[typing.Annotated[int, Strict(strict=True)], typing.Annotated[float, Strict(strict=True)]]
Release Version
Python 3.12.1
pydantic 2.5.3
polyfactory 2.14.0
Platform
[ ] Linux
[X] Mac
[ ] Windows
[ ] Other (Please specify in the description above)
@berkaycagir thanks for reporting this! I can reproduce this, and it most likely has to do with the changes introduced in #468 which slightly changed how unions are handled.
Description
One of our
pydantic
models has the following field definition among others:In
polyfactory
2.13.0, a boilerplate factory for this model worked fine. However, with the upgrade to 2.14.0, we started seeing the exception in the title.URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
No response
Logs
Release Version
pydantic
2.5.3polyfactory
2.14.0Platform