tortoise / tortoise/tortoise-orm
An error occurs when using the save method to save data : concurrent.futures._base.CancelledError
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
Method of saving data using tortoise ORM:
await XXX.save()
Then errors will be reported in the execution process, not every time. It is an accidental phenomenon.
The version used is tortoise-orm==0.17.7
To Reproduce

Additional context
File "/handler/trigger_handler.py", line 116, in deal_no
await check_res.save()
File "/usr/local/lib/python3.7/site-packages/tortoise/models.py", line 943, in save
await executor.execute_update(self, update_fields)
File "/usr/local/lib/python3.7/site-packages/tortoise/backends/base/executor.py", line 317, in execute_update
self.get_update_sql(update_fields, arithmetic_or_function), values
File "/usr/local/lib/python3.7/site-packages/tortoise/backends/mysql/client.py", line 44, in translate_exceptions_
return await func(self, *args)
File "/usr/local/lib/python3.7/site-packages/tortoise/backends/mysql/client.py", line 199, in execute_query
await cursor.execute(query, values)
File "/usr/local/lib/python3.7/site-packages/aiomysql/cursors.py", line 239, in execute
await self._query(query)
File "/usr/local/lib/python3.7/site-packages/aiomysql/cursors.py", line 457, in _query
await conn.query(q)
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 428, in query
await self._read_query_result(unbuffered=unbuffered)
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 622, in _read_query_result
await result.read()
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 1105, in read
first_packet = await self.connection._read_packet()
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 561, in _read_packet
packet_header = await self._read_bytes(4)
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 598, in _read_bytes
data = await self._reader.readexactly(num_bytes)
File "/usr/local/lib/python3.7/asyncio/streams.py", line 679, in readexactly
await self._wait_for_data('readexactly')
File "/usr/local/lib/python3.7/asyncio/streams.py", line 473, in _wait_for_data
await self._waiter
concurrent.futures._base.CancelledError
Please take the time to take a look. Thank you very much
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tortoise/models.py and tortoise/backends/base/executor.py, following the save path into tortoise/backends/mysql/client.py. Reproduce the intermittent failure with the reported save call and MySQL setup, then trace how the cancellation is surfaced. Done means the failure is understood and a verified regression test or fix is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100