Bug: Setting ge
and multiple_of
but not le
constraints causes invalid values to be generated
#503
Open
2 of 4 tasks
Labels
bug
Something isn't working
Description
I am using Polyfactory with Pydantic, and it appears that if you create a field with both
ge
andmultiple_of
set, but notle
orlt
, then Polyfactory will generate values that don't satisfy all the constraints. For example, if you setge
to 10 andmultiple_of
to 3, then Polyfactory appears to always generate a value of 3, which fails to satisfy the>= 10
constraint.It looks like the bug is in
polyfactory.value_generators.constrained_numbers
'sgenerate_constrained_number()
function. In that function, if bothminimum
andmultiple_of
are set to non-None values, butmaximum
is None, then it'll take the earliest exit by immediately returningmultiple_of
, even ifmultiple_of
may not satisfy theminimum
constraint.URL to code causing the issue
No response
MCVE
Steps to reproduce
1. Install both pydantic and polyfactory 2. Save the code snippet above to a file (e.g. main.py) 3. Execute the file (e.g. `python3 main.py`)
Screenshots
No response
Logs
Release Version
4.14.1
Platform
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: