Open richardxia opened 6 months ago
@richardxia thanks for reporting this! I think you're right in your analysis of generate_constrained_number
being the issue as well. Would you be willing to raise a PR fixing this?
No problem, I'd be happy to take a stab at fixing this.
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
Screenshots
No response
Logs
Release Version
4.14.1
Platform