tortoise / tortoise-orm

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

Anyone use this project in asyncio.create_task method successfully? #1321

Open iyuhang opened 1 year ago

iyuhang commented 1 year ago

I always get the this error:

asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress

Traceback (most recent call last): File "/Users/apple/SynologyDrive/code/rena_sanic/account/logic/user_base.py", line 81, in update_profile profile: Profile = await user.profile File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/queryset.py", line 1006, in _execute instance_list = await self._db.executor_class( File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/base/executor.py", line 130, in executeselect , raw_results = await self.db.execute_query(query.get_sql()) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/base_postgres/client.py", line 34, in _translate_exceptions return await self._translate_exceptions(func, *args, *kwargs) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 82, in _translate_exceptions return await func(self, args, *kwargs) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 143, in execute_query rows = await connection.fetch(params) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/asyncpg/connection.py", line 621, in fetch return await self._execute( File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/asyncpg/connection.py", line 1659, in execute result, = await self.execute( File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/asyncpg/connection.py", line 1684, in execute return await self._do_execute( File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/asyncpg/connection.py", line 1731, in _do_execute result = await executor(stmt, None) File "asyncpg/protocol/protocol.pyx", line 181, in bind_execute File "asyncpg/protocol/protocol.pyx", line 707, in asyncpg.protocol.protocol.BaseProtocol._check_state asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress

or this error:

asyncpg.exceptions._base.InterfaceError: cannot call Connection.fetch(): connection has been released back to the pool

Traceback (most recent call last): File "/Users/apple/SynologyDrive/code/rena_sanic/account/views.py", line 239, in run_in_bg await UserBase().update_profile(user=user, data=data, request=request) File "/Users/apple/SynologyDrive/code/rena_sanic/account/logic/user_base.py", line 81, in update_profile profile: Profile = await user.profile File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/queryset.py", line 1006, in _execute instance_list = await self._db.executor_class( File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/base/executor.py", line 130, in executeselect , raw_results = await self.db.execute_query(query.get_sql()) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/base_postgres/client.py", line 34, in _translate_exceptions return await self._translate_exceptions(func, *args, *kwargs) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 82, in _translate_exceptions return await func(self, args, *kwargs) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 143, in execute_query rows = await connection.fetch(params) File "/Users/apple/opt/anaconda3/envs/sanic/lib/python3.9/site-packages/asyncpg/pool.py", line 55, in call_con_method raise exceptions.InterfaceError( asyncpg.exceptions._base.InterfaceError: cannot call Connection.fetch(): connection has been released back to the pool

waketzheng commented 1 year ago

What's the content of UserBase?