tortoise / tortoise/tortoise-orm
Error caused by %
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
DEBUG:tortoise.db_client:UPDATE `order` SET `type`=%s WHERE `type`=17 AND (CAST(`result` AS CHAR) LIKE '%****%' OR CAST(`result` AS CHAR) LIKE '%----%'): [16]
ERROR:telethon.client.updates:Unhandled exception on handler
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/telethon/client/updates.py", line 570, in _dispatch_update
await callback(event)
File "x.py", line 615, in handler
await query(event)
File "x.py", line 306, in query
await Order.filter(Q(type=17) & (Q(result__contains='****') | Q(result__contains='----'))).update(type=16)
File "/usr/local/lib/python3.8/dist-packages/tortoise/queryset.py", line 1111, in _execute
return (await self._db.execute_query(str(self.query), self.values))[0]
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/mysql/client.py", line 44, in translate_exceptions_
return await func(self, *args)
File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/mysql/client.py", line 199, in execute_query
await cursor.execute(query, values)
File "/usr/local/lib/python3.8/dist-packages/aiomysql/cursors.py", line 237, in execute
query = query % self._escape_args(args, conn)
The initial suspicion is caused by contains, how can I solve this problem
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/backends/mysql/client.py and the execute_query path shown in the traceback, then inspect tortoise/queryset.py where the SQL and values are passed to the backend. Reproduce the filter using Q(result__contains=...) and verify that MySQL executes the generated LIKE query without the formatting error while preserving the intended wildcard patterns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100