tortoise / tortoise-orm

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

Model.get().delete() fails #923

Open SegmentationViolator opened 3 years ago

SegmentationViolator commented 3 years ago

Describe the bug raises this exception instead of deleting the model.

Traceback (most recent call last):
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 30, in translate_exceptions_
    return await func(self, query, *args)
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 136, in execute_query
    rows = await connection.execute_fetchall(query, values)
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/aiosqlite/core.py", line 203, in execute_fetchall
    return await self._execute(self._execute_fetchall, sql, parameters)
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/aiosqlite/core.py", line 129, in _execute
    return await future
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/aiosqlite/core.py", line 81, in _execute_fetchall
    cursor = self._conn.execute(sql, parameters)
sqlite3.OperationalError: near "LIMIT": syntax error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/data/com.termux/files/home/workspaces/Ai/src/components/general.py", line 185, in on_guild_message_create
    await (
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/tortoise/queryset.py", line 1057, in _execute
    return (await self._db.execute_query(str(self.query)))[0]
  File "/data/data/com.termux/files/home/workspaces/Ai/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 32, in translate_exceptions_
    raise OperationalError(exc)
tortoise.exceptions.OperationalError: near "LIMIT": syntax error

To Reproduce

MyModel.get(...).delete()

Expected behavior delete the specific model and not raise any exceptions.

long2ice commented 3 years ago

You should enable --enable-update-limit

SegmentationViolator commented 3 years ago

python --enable-update-limit ?

long2ice commented 3 years ago

https://stackoverflow.com/questions/39033727/enable-limit-in-update-statement-sqlite

usernein commented 2 years ago

Hmmm any other way than rebuilding? For my application, telling all users to rebuild sqlite is not a good solution. Also, was this change documented? It was working fine before, i'd like to know why it changed, requiring this modification into sqlite

SHREYAS290601 commented 1 year ago

You can use filter instead of get

waketzheng commented 1 year ago

I got the same error when running make test_sqlite, and solved it by the following steps(My system is MacOS):

  1. Install the latest version of sqlite3 with update-limit enabled
    
    STEM=sqlite-src-3410000
    FILE=$STEM.zip

if [ -d $STEM ]; then echo Folder $STEM exists. else if [ -f $FILE ]; then echo File $FILE exists. else wget https://www.sqlite.org/$(date +'%Y')/$FILE fi unzip $FILE fi

cd $STEM && \ ./configure --prefix=/usr/local --disable-static --enable-update-limit && \ make sqlite3.c && \ make install && \ echo Done.

https://stackoverflow.com/a/75553632/9586338
2. make symbolic link to use it
- show sqlite3 version in python
```bash
python -c 'import _sqlite3 as print(m.sqlite_version)
# 3.40.1