litestar-org/polyfactory

Bug: Integer generation when constrained by lower or equal

lgeo3 opened this issue · 2 comments

lgeo3 commented

There seems to be an issue with the way constrained int are generated, so it seems to be impossible to get all possible values when for example we have a int with ge=1, and le=3

the possible values should be [1, 2, 3]
but with the generator we get only [1, 2]
for example

from pydantic import Field, BaseModel
from pydantic_factories import ModelFactory


class MyModel(BaseModel):
    my_field: int = Field(ge=1, le=3)


class MyFactory(ModelFactory):
    __model__ = MyModel


MyFactory.build()

I think it can be solved by replacing int casting by round function here

https://github.com/starlite-api/pydantic-factories/blob/da3495f295b8126224051fe4c3e46fa0d6970f34/pydantic_factories/value_generators/primitives.py#L21

What do you think ?

Well, we should definitely check it out 😁.

Currently we've begun work on V2. So we will aim to fix this as part of that.

please check this against main and see if this is still a problem