Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntField: constraints not taken into account #1853

Open
markus-96 opened this issue Jan 17, 2025 · 0 comments · May be fixed by #1872
Open

IntField: constraints not taken into account #1853

markus-96 opened this issue Jan 17, 2025 · 0 comments · May be fixed by #1872

Comments

@markus-96
Copy link
Contributor

Describe the bug
The IntField has the property constraints. It contains the constraints ge and le. These constraints are not taken into account (in any place as far as I can tell) or they should be reflected by a validator.

To Reproduce

from tortoise import models, fields, run_async
from tortoise.contrib.test import init_memory_sqlite


class Acc(models.Model):
    id = fields.IntField(pk=True)
    some = fields.IntField()


async def main():
    constraints_id = Acc._meta.fields_map.get('id').constraints  # {'ge': -2147483648, 'le': 2147483647}
    too_high_id = constraints_id.get('le') + 1
    constraints_some = Acc._meta.fields_map.get('some').constraints  # {'ge': -2147483648, 'le': 2147483647}
    too_low_some = constraints_some.get('ge') - 1
    acc = Acc(id=too_high_id, some=too_low_some)  # this should throw an error
    await acc.save()  # or maybe this


if __name__ == '__main__':
    run_async(init_memory_sqlite(main)())

Expected behavior
Either the constraints should match the capabilities of the DB or the constraints should be checked beforehand. And an error should be thrown.

Additional context
The produced Pydantic Model by pydantic_model_creator would check those constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant