tarantool / tarantool-python

Python client library for Tarantool
https://www.tarantool.io
BSD 2-Clause "Simplified" License
100 stars 48 forks source link

Can't pass `None` as function argument via `call` #136

Closed a1tus closed 5 years ago

a1tus commented 5 years ago

I have a function with several args any of which can be nil. Very simplified example.

function test(arg1, arg2)
  if not arg2 then
    arg2 = 0
  end
  return arg1 + arg2
end

While using it from LUA console like test(1) or test(1, nil) everything is fine.

But when I try to call it from python I get error:

>> connection.call('test', [1, None])
DatabaseError: (32, '[string "function test(arg1, arg2)..."]:5: attempt to perform arithmetic on \'number\' and \'void *\'')

So arg2 is void * and its type in this case is not nil but cdata which evaluates to true.

P.S. I know that I can use dict that will contains all params as single function arg but for API clarity it would be nice to solve this issue.

sharonovd commented 5 years ago

Please see https://github.com/tarantool/doc/issues/753

Don't use if not arg2 then, use if arg2 ~= nil then