tortoise / tortoise/tortoise-orm

help!!Occasional bugs with tortoise + aiomysql running on sanic

Open
#1,034 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Describe the bug
Version: tortoise-orm==0.17.7
A clear and concise description of what the bug is.

To Reproduce
Unable to re, only occasionally does this error occur

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'images'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 3296, in viewRecord
scheme_obj = await Scheme.get_or_none(uni_id=scheme_id)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'watch_user_id'
Traceback (most recent call last):
File "/data/frontend/api.py", line 1446, in schemeList
s['sale_num'] = await Order.filter(scheme_id=s['uni_id'], status=1).count()
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 1174, in _execute
count = list(dict(result[0]).values())[0] - self.offset
IndexError: list index out of range
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'nickname'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 474, in getSubscribe
wx_user_obj = await WXUserInfo.get_or_none(user_id=request.ctx.uid, app_id=ACTIVE_WX_APP_ID)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'COUNT(*)'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'user_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 474, in getSubscribe
wx_user_obj = await WXUserInfo.get_or_none(user_id=request.ctx.uid, app_id=ACTIVE_WX_APP_ID)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'username'
Traceback (most recent call last):
File "/data/frontend/api.py", line 1441, in schemeList
s['create_time'] = s['create_time'].strftime("%Y-%m-%d %H:%M:%S") if s['create_time'] is not None else ''
KeyError: 'create_time'
Traceback (most recent call last):
File "/data/frontend/api.py", line 3296, in viewRecord
scheme_obj = await Scheme.get_or_none(uni_id=scheme_id)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 922, in _execute
raise MultipleObjectsReturned("Multiple objects returned, expected exactly one")
tortoise.exceptions.MultipleObjectsReturned: Multiple objects returned, expected exactly one
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'user_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 738, in get
order_objs = await Order.filter(scheme_id=scheme_obj.uni_id, pay_user_id=view_user_obj.id)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'has_limit_time'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'images'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 683, in get
scheme_objs = await Scheme.filter(uni_id=id)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'nickname'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'nickname'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 679, in get
view_user_objs = await UserInfo.filter(username=username)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'has_limit_time'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'user_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/frontend/api.py", line 474, in getSubscribe
wx_user_obj = await WXUserInfo.get_or_none(user_id=request.ctx.uid, app_id=ACTIVE_WX_APP_ID)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 908, in _execute
instance_list = await self._db.executor_class(
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/base/executor.py", line 134, in execute_select
instance: "Model" = self.model._init_from_db(
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 734, in _init_from_db
setattr(self, key, meta.fields_map[key].to_python_value(value))
KeyError: 'username'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/tortoise/models.py", line 717, in _init_from_db
setattr(self, model_field, kwargs[key])
KeyError: 'username'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tortoise/models.py, queryset.py, and backends/base/executor.py, using the reported tortoise-orm==0.17.7 setup with aiomysql and Sanic. Compare the listed KeyError, IndexError, and MultipleObjectsReturned traces and isolate a reproducible failure; done means the underlying intermittent error is identified and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.