libsql-experimental-python icon indicating copy to clipboard operation
libsql-experimental-python copied to clipboard

Savepoints support

Open ipmb opened this issue 2 years ago • 5 comments

https://sqlite.org/lang_savepoint.html

I'm trying to get a Django database backend running and this is the current blocker. You can see the error in this test run: https://github.com/lincolnloop/django-libsql/actions/runs/6438992639/job/17486170095

Here is the relevant portion of the traceback and the SQL it is trying to run.

  File "/Users/pete/projects/lincolnloop/django-libsql/django/django/db/backends/utils.py", line 87, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: unsupported statement
>>> import pdb; pdb.pm()
> /Users/pete/projects/lincolnloop/django-libsql/django/django/db/backends/utils.py(87)_execute()
-> return self.cursor.execute(sql)
(Pdb) sql
'SAVEPOINT "s8177341184_x1"'

ipmb avatar Oct 07 '23 04:10 ipmb

Hi! Savepoint support will be added server-side very soon, it's in review at the moment: https://github.com/libsql/sqld/pull/472

psarna avatar Oct 07 '23 07:10 psarna

Now that this is in on the server-side, are there also changes that need to be done in this library? I'm getting an error trying to use it against a 0.21.9 sqld Docker container running locally:

$ python
Python 3.11.0 (main, Oct 24 2022, 17:18:58) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import libsql_experimental as libsql
>>> c = libsql.connect(database="test.db", sync_url="http://libsql1.local:8080/", auth_token="")
>>> c.execute('SAVEPOINT "test"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported statement

ipmb avatar Oct 10 '23 23:10 ipmb

hm, right, newer versions of the client lib also parse statements to decide if they are readonly or writes... /cc @penberg @LucioFranco . I'll cook a client patch and keep you posted, thanks for reporting!

psarna avatar Oct 11 '23 08:10 psarna

@ipmb should be fixed by https://github.com/libsql/libsql-experimental-python/commit/0224c34905e86df6f516592a301bfd9c03fd01ca

penberg avatar Nov 03 '23 12:11 penberg

Seeing this now

$ RUST_BACKTRACE=1 python
Python 3.11.2 (main, Mar 23 2023, 18:34:48) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import libsql_experimental as libsql_client
>>> conn = libsql_client.connect(database="tmp.db", sync_url="http://testdb.local:8080", auth_token="")
>>> conn.execute('SAVEPOINT "test"')
thread '<unnamed>' panicked at /root/.cargo/git/checkouts/libsql-311658d335deb3b1/52814a9/libsql/src/replication/connection.rs:136:13:
replication connection has reached an invalid state, started with Init
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
   2: libsql::replication::connection::RemoteConnection::should_execute_local
   3: <libsql::replication::connection::RemoteConnection as libsql::connection::Conn>::prepare::{{closure}}
   4: tokio::runtime::park::CachedParkThread::block_on
   5: tokio::runtime::context::runtime::enter_runtime
   6: libsql_experimental::_::<impl libsql_experimental::Connection>::__pymethod_execute__
   7: pyo3::impl_::trampoline::trampoline
   8: libsql_experimental::_::<impl pyo3::impl_::pyclass::PyMethods<libsql_experimental::Connection> for pyo3::impl_::pyclass::PyClassImplCollector<libsql_experimental::Connection>>::py_methods::ITEMS::trampoline
   9: method_vectorcall_FASTCALL_KEYWORDS
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Objects/descrobject.c:426:24
  10: _PyObject_VectorcallTstate
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/./Include/internal/pycore_call.h:92:11
  11: PyObject_Vectorcall
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Objects/call.c:299:12
  12: _PyEval_EvalFrameDefault
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/ceval.c:4772:23
  13: _PyEval_EvalFrame
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/./Include/internal/pycore_ceval.h:73:16
  14: _PyEval_Vector
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/ceval.c:6435:24
  15: PyEval_EvalCode
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/ceval.c:1154:21
  16: run_eval_code_obj
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/pythonrun.c:1714:9
  17: run_mod
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/pythonrun.c:1735:19
  18: PyRun_InteractiveOneObjectEx
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/pythonrun.c:261:9
  19: _PyRun_InteractiveLoopObject
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/pythonrun.c:138:15
  20: _PyRun_AnyFileObject
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/pythonrun.c:73:15
  21: PyRun_AnyFileExFlags
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Python/pythonrun.c:105:15
  22: pymain_run_stdin
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Modules/main.c:509:15
  23: pymain_run_python
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Modules/main.c:604:21
  24: Py_RunMain
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Modules/main.c:680:5
  25: pymain_main
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Modules/main.c:710:12
  26: Py_BytesMain
             at /tmp/python-build.20230323183322.344971/Python-3.11.2/Modules/main.c:734:12
  27: __libc_start_call_main
             at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  28: __libc_start_main_impl
             at ./csu/../csu/libc-start.c:392:3
  29: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: replication connection has reached an invalid state, started with Init

ipmb avatar Jan 04 '24 00:01 ipmb