tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.58k stars 379 forks source link

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

Open ChangeMoreNate opened 2 years ago

ChangeMoreNate commented 2 years ago

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'

xlliu commented 2 years ago

same question +1

Huangvivi commented 2 years ago

same question +1

long2ice commented 2 years ago

What about try upgrade?

Chaotic-chaos commented 1 year ago

Same issue here... It seems that after some time, the model cannot query from the database. Waiting for any possible solutions.

hellokaton commented 1 year ago

same question +1

minghuiruan commented 1 year ago

@long2ice I have the same issues too with the latest version, any update for this? I have some production service running this code and this issue keep happens very ofter, and I have to restart the server to resolve this