tortoise-orm
tortoise-orm copied to clipboard
Model.get().delete() fails
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.
You should enable --enable-update-limit
python --enable-update-limit
?
https://stackoverflow.com/questions/39033727/enable-limit-in-update-statement-sqlite
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
You can use filter instead of get
I got the same error when running make test_sqlite
, and solved it by the following steps(My system is MacOS):
- 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
python -c 'import _sqlite3 as print(m.sqlite_version)
# 3.40.1
- find the path of it
sudo find / -name "*sqlite3*"
# /usr/local/Cellar/sqlite/3.40.1
- change it to use the new one
cd /usr/local/Cellar/sqlite/3.40.1/lib
ls -lh .
mv libsqlite3.a libsqlite3.a_3.40.1
ln -s /usr/local/lib/libsqlite3.a libsqlite3.a
mv libsqlite3.0.dylib libsqlite3.0.dylib_3.40.1
ln -s /usr/local/lib/libsqlite3.0.dylib libsqlite3.0.dylib