tortoise / tortoise-orm

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

F expression with BigIntType throwing type error #1285

Closed pravin-d closed 1 year ago

pravin-d commented 1 year ago

Describe the bug F expression on BigIntField not work

Throws the following error TypeError: int() argument must be a string, a bytes-like object or a real number, not 'ArithmeticExpression'

CallStack

File "/home/handlers/custom.py", line 97, in on_buy_kalam
    await models.Balances.filter(id=1).update(quantity = F('quantity') - 1)
  File "/home/.pyenv/versions/3.10.7/lib/python3.10/site-packages/dipdup/models.py", line 428, in _execute
    model._set_kwargs(self.update_kwargs)
  File "/home/.pyenv/versions/3.10.7/lib/python3.10/site-packages/tortoise/models.py", line 698, in _set_kwargs
    setattr(self, key, field_object.to_python_value(value))
  File "/home/versions/3.10.7/lib/python3.10/site-packages/tortoise/fields/base.py", line 224, in to_python_value
    value = self.field_type(value)  # pylint: disable=E1102
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'ArithmeticExpression'

To Reproduce Model

class Test(Model):
  bigInt = fields.BigIntField(default = 0)

Elsewhere

Test.filter(id=1).update(bigInt = F('bigInt') + 1)

Expected behavior increment the bigInt field by 1

pravin-d commented 1 year ago

Does not see to be a problem with Tortoise