asynctnt icon indicating copy to clipboard operation
asynctnt copied to clipboard

Support for decimal and float types for arithmetic operations in update

Open first-muchacho opened this issue 1 year ago • 0 comments

TypeError when trying to update a numeric or decimal field using an addition or subtraction operation using the Decimal or float type.

Example: init.lua

box.cfg{listen = 3301}

space_list = box.space

require "os"

if not box.schema.user.exists(os.getenv("TARANTOOL_USER_NAME")) then
    box.schema.user.create(os.getenv("TARANTOOL_USER_NAME"), {password = os.getenv("TARANTOOL_USER_PASSWORD"),
                                             if_not_exists = true})
    box.schema.user.grant(os.getenv("TARANTOOL_USER_NAME"),'read,write,execute,create,drop','universe')
end

if not space_list['customer'] then
    s = box.schema.space.create('customer')

    s:format({
        {name = 'customer_id', type = 'unsigned'},
        {name = 'username', type = 'string', is_nullable=true},
        {name = 'is_active', type = 'boolean'},
        {name = 'balance', type = 'number', is_nullable=true}
    })

    s:create_index('primary', {
        type = 'hash',
        parts = {'customer_id'}
    })
end

example.py

import os
import asynctnt
import asyncio


async def main():
    conn = asynctnt.Connection(
        host='127.0.0.1',
        port=3301,
        username=os.getenv('TARANTOOL_USER_NAME'),
        password=os.getenv('TARANTOOL_USER_PASSWORD')
    )
    await conn.connect()

    result = await conn.update('customer', [1], [('+', 'balance', 23.65)])

    print(f'RESULT: {result}')

    await conn.disconnect()


asyncio.run(main())

stderr

... File "asynctnt\iproto\db.pyx", line 403, in asynctnt.iproto.protocol.Db.update File "asynctnt\iproto\db.pyx", line 206, in asynctnt.iproto.protocol.Db._update File "asynctnt\iproto\protocol.pyx", line 490, in asynctnt.iproto.protocol.BaseProtocol._execute_normal File "asynctnt\iproto\requests/base.pyx", line 18, in asynctnt.iproto.protocol.BaseRequest.encode File "asynctnt\iproto\requests/update.pyx", line 7, in asynctnt.iproto.protocol.UpdateRequest.encode_body File "asynctnt\iproto\requests/update.pyx", line 220, in asynctnt.iproto.protocol.encode_request_update File "asynctnt\iproto\requests/update.pyx", line 91, in asynctnt.iproto.protocol.encode_update_ops TypeError: int argument required for Arithmetic and Delete operations

first-muchacho avatar Apr 19 '24 11:04 first-muchacho