tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.38k stars 356 forks source link

Can not to use relation to table with unsigned pk #1602

Closed mixartemev closed 1 month ago

mixartemev commented 1 month ago

Describe the bug

pydantic_core._pydantic_core.ValidationError: 1 validation error for ListItem
msg.chat_id
  Input should be greater than or equal to 1 [type=greater_than_equal, input_value=-1001294902609, input_type=int]
    For further information visit https://errors.pydantic.dev/2.7/v/greater_than_equal

To Reproduce Just to have negative values in PK field of related table

Expected behavior Do not get validation error

Additional context Cause: constraint ge is reseting to 1 for relational field (where self.reference is not None) https://github.com/tortoise/tortoise-orm/blob/345af1744a1c661da1ddb5245d31aba688ce48a1/tortoise/fields/data.py#L123

abondar commented 1 month ago

Yeah, it's a little bit problematic

Probably should just delete dynamic lower bound, as we don't enforce it anyhow on db level Will remove it in next version

abondar commented 1 month ago

Should be fixed in 0.21.0, now int fields are always signed