Describe the bug
When using nested select_related of form:
'modelA__modelB'
I'm getting a KeyError when ORM tries to assign values to modelB.
An issue arises since kwargs values passed to _init_from_db function getting sliced version of model attribute's name, for example, instead of passing 'city_obj' attribute, 'city_ob' is being passed to kwargs, same way instead of attribute 'building', 'buildin' is being passed etc.
Actual error:
File "/usr/local/lib/python3.9/site-packages/tortoise/queryset.py", line 1008, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.9/site-packages/tortoise/backends/base/executor.py", line 155, in execute_select
obj = model._init_from_db(
File "/usr/local/lib/python3.9/site-packages/tortoise/models.py", line 747, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'buildin'
Describe the bug When using nested select_related of form: 'modelA__modelB' I'm getting a KeyError when ORM tries to assign values to modelB.
An issue arises since kwargs values passed to
_init_from_db
function getting sliced version of model attribute's name, for example, instead of passing 'city_obj' attribute, 'city_ob' is being passed to kwargs, same way instead of attribute 'building', 'buildin' is being passed etc.Actual error:
File "/usr/local/lib/python3.9/site-packages/tortoise/queryset.py", line 1008, in _execute instance_list = await self._db.executor_class( File "/usr/local/lib/python3.9/site-packages/tortoise/backends/base/executor.py", line 155, in execute_select obj = model._init_from_db( File "/usr/local/lib/python3.9/site-packages/tortoise/models.py", line 747, in _init_from_db setattr(self, key, meta.fields_map[key].to_python_value(value)) KeyError: 'buildin'
ORM version: tortoise-orm==0.19.3