tarantool/tarantool-python

Exception on connection to server with foreign_key

sergeybe opened this issue · 2 comments

I'm trying to run the next simple server code with foreign_key:

box.cfg{listen = 3301}

box.once("some_bug", function()
    box.schema.user.grant('guest', 'read,write,execute,create,alter,drop,usage,session', 'universe')

    table1 = box.schema.space.create('table1')
    table1:format({
        { name = 'id', type = 'integer' },
        { name = 'title', type = 'string' },
    })

    table2 = box.schema.space.create('videohash')
    table2:format({
        { name = 'id', type = 'integer' },
        { name = 'table1_id', type = 'integer', 
          foreign_key = { fk_video = { space = 'table1', field = 'id' }} },   -- Problem line here
        { name = 'name', type = 'string' },
    })
end)

require('console').start()

Then I'm trying to run:

% python
Python 3.11.2 (main, Feb 16 2023, 03:07:35) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tarantool
>>> connection = tarantool.Connection('localhost', 3301)
Traceback (most recent call last):
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 163, in __init__
    format_raw = to_unicode_recursive(space_row[6], 3)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 74, in to_unicode_recursive
    val = to_unicode_recursive(val, max_depth - 1)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 67, in to_unicode_recursive
    val = to_unicode_recursive(val, max_depth - 1)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 66, in to_unicode_recursive
    key = to_unicode_recursive(key, max_depth - 1)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 61, in to_unicode_recursive
    raise RecursionError('Max recursion depth is reached')
tarantool.schema.RecursionError: Max recursion depth is reached

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/connection.py", line 1042, in connect
    self.load_schema()
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/connection.py", line 1261, in load_schema
    self.schema.fetch_space_all()
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 299, in fetch_space_all
    SchemaSpace(row, self.schema)
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/schema.py", line 166, in __init__
    raise SchemaError(errmsg)
tarantool.error.SchemaError: Unexpected space format structure: Max recursion depth is reached

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/connection.py", line 812, in __init__
    self.connect()
  File "/Users/user/.virtualenvs/test1/lib/python3.11/site-packages/tarantool/connection.py", line 1049, in connect
    raise NetworkError(e)
tarantool.error.NetworkError: Unexpected space format structure: Max recursion depth is reached
>>>

When I comment the line with foreign_key my code can connect without problem.
Please help.

Thank you for the issue. It seems like a bug, I'll dig deeper a bit later.

Seems like this tight recursion limit (my bad idea) plays poor in terms of compatibility with future tarantool versions. I think there should be some limit, but not a such tight one.