Skip to content

OperationalError: (sqlite3.OperationalError) no active connection #786

Description

@sentry

Sentry Issue: COOLQBOT-116

ValueError: no active connection
  File "sqlalchemy/dialects/sqlite/aiosqlite.py", line 157, in execute
    _cursor: AsyncIODBAPICursor = self.await_(self._connection.cursor())  # type: ignore[arg-type] # noqa: E501
  File "sqlalchemy/util/_concurrency_py3k.py", line 132, in await_only
    return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
  File "sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn
    value = await result
  File "aiosqlite/core.py", line 151, in cursor
    return Cursor(self, await self._execute(self._conn.cursor))
  File "aiosqlite/core.py", line 73, in _conn
    raise ValueError("no active connection")

OperationalError: no active connection
  File "sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "sqlalchemy/engine/default.py", line 951, in do_execute
    cursor.execute(statement, parameters)
  File "sqlalchemy/dialects/sqlite/aiosqlite.py", line 180, in execute
    self._adapt_connection._handle_exception(error)
  File "sqlalchemy/dialects/sqlite/aiosqlite.py", line 336, in _handle_exception
    raise self.dbapi.sqlite.OperationalError(

OperationalError: (sqlite3.OperationalError) no active connection
[SQL: SELECT hello_hello.id, hello_hello.target, hello_hello.bot_id 
FROM hello_hello 
WHERE hello_hello.bot_id = ?]
[parameters: ('355018731',)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
(15 additional frame(s) were not displayed)
...
  File "/app/src/plugins/morning/plugins/hello/__init__.py", line 41, in hello_on_connect
    groups = (await session.scalars(select(Hello).where(Hello.bot_id == bot.self_id))).all()

2026-02-19 10:07:32.081 | ERROR    | nonebot:handle_exception:167 - Error when running WebSocketConnection hook:Traceback (most recent call last):

  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 157, in execute
    _cursor: AsyncIODBAPICursor = self.await_(self._connection.cursor())  # type: ignore[arg-type] # noqa: E501
                                  |    |      |    -> <member '_connection' of 'AsyncAdapt_aiosqlite_cursor' objects>
                                  |    |      -> <sqlalchemy.dialects.sqlite.aiosqlite.AsyncAdapt_aiosqlite_cursor object at 0x7e74a6f34880>
                                  |    -> <member 'await_' of 'AsyncAdapt_aiosqlite_cursor' objects>
                                  -> <sqlalchemy.dialects.sqlite.aiosqlite.AsyncAdapt_aiosqlite_cursor object at 0x7e74a6f34880>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 132, in await_only
    return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
           |       |             -> <aiosqlite.context.Result object at 0x7e74606aa290>
           |       -> <attribute 'parent' of 'greenlet.greenlet' objects>
           -> <_AsyncIoGreenlet object at 0x7e749902ae80 (otid=0x7e74a520c330) dead>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn
    value = await result
                  -> <aiosqlite.context.Result object at 0x7e74606aa290>
  File "/app/.venv/lib/python3.14/site-packages/aiosqlite/core.py", line 151, in cursor
    return Cursor(self, await self._execute(self._conn.cursor))
           |      |           |    |        |    -> <property object at 0x7e74a4a27ce0>
           |      |           |    |        -> <Connection(Thread-3, stopped daemon 139038187718336)>
           |      |           |    -> <function Connection._execute at 0x7e74a4a3e980>
           |      |           -> <Connection(Thread-3, stopped daemon 139038187718336)>
           |      -> <Connection(Thread-3, stopped daemon 139038187718336)>
           -> <class 'aiosqlite.cursor.Cursor'>
  File "/app/.venv/lib/python3.14/site-packages/aiosqlite/core.py", line 73, in _conn
    raise ValueError("no active connection")

ValueError: no active connection


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
    |    |       -> <function DefaultDialect.do_execute at 0x7e74a45e9380>
    |    -> <sqlalchemy.dialects.sqlite.aiosqlite.SQLiteDialect_aiosqlite object at 0x7e745f70fb10>
    -> <sqlalchemy.engine.base.Connection object at 0x7e745acbbb10>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/engine/default.py", line 951, in do_execute
    cursor.execute(statement, parameters)
    |      |       |          -> ('355018731',)
    |      |       -> 'SELECT hello_hello.id, hello_hello.target, hello_hello.bot_id \nFROM hello_hello \nWHERE hello_hello.bot_id = ?'
    |      -> <function AsyncAdapt_aiosqlite_cursor.execute at 0x7e74a4a0b1c0>
    -> <sqlalchemy.dialects.sqlite.aiosqlite.AsyncAdapt_aiosqlite_cursor object at 0x7e74a6f34880>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 180, in execute
    self._adapt_connection._handle_exception(error)
    |    -> <member '_adapt_connection' of 'AsyncAdapt_aiosqlite_cursor' objects>
    -> <sqlalchemy.dialects.sqlite.aiosqlite.AsyncAdapt_aiosqlite_cursor object at 0x7e74a6f34880>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py", line 336, in _handle_exception
    raise self.dbapi.sqlite.OperationalError(
          |    -> <member 'dbapi' of 'AsyncAdapt_aiosqlite_connection' objects>
          -> <AdaptedConnection <Connection(Thread-3, stopped daemon 139038187718336)>>

sqlite3.OperationalError: no active connection


The above exception was the direct cause of the following exception:



Traceback (most recent call last):

> File "/app/.venv/lib/python3.14/site-packages/nonebot/utils.py", line 243, in run_coro_with_catch
    return await coro
                 -> <coroutine object Dependent.__call__ at 0x7e74a6edf400>
  File "/app/.venv/lib/python3.14/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
                 |    |             |         |    |    |       -> {'bot': Bot(type='OneBot V11', self_id='355018731'), 'session': <sqlalchemy.ext.asyncio.scoping.async_scoped_session object a...
                 |    |             |         |    |    -> <function hello_on_connect at 0x7e749c05a770>
                 |    |             |         |    -> Dependent(call=hello_on_connect)
                 |    |             |         -> ~R
                 |    |             -> <class 'collections.abc.Awaitable'>
                 |    -> typing.Callable
                 -> <function cast at 0x7e74a84c81a0>

  File "/app/src/plugins/morning/plugins/hello/__init__.py", line 41, in hello_on_connect
    groups = (await session.scalars(select(Hello).where(Hello.bot_id == bot.self_id))).all()
                    |       |       |      |            |     |         |   -> '355018731'
                    |       |       |      |            |     |         -> Bot(type='OneBot V11', self_id='355018731')
                    |       |       |      |            |     -> <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7e749c035d00>
                    |       |       |      |            -> <class 'src.plugins.morning.plugins.hello.models.Hello'>
                    |       |       |      -> <class 'src.plugins.morning.plugins.hello.models.Hello'>
                    |       |       -> <function select at 0x7e74a46796f0>
                    |       -> <function async_scoped_session.scalars at 0x7e749cdabe20>
                    -> <sqlalchemy.ext.asyncio.scoping.async_scoped_session object at 0x7e745ce27b60>

  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/ext/asyncio/scoping.py", line 1099, in scalars
    return await self._proxied.scalars(
                 |    -> <property object at 0x7e749cd33ba0>
                 -> <sqlalchemy.ext.asyncio.scoping.async_scoped_session object at 0x7e745ce27b60>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/ext/asyncio/session.py", line 562, in scalars
    result = await self.execute(
                   |    -> <function AsyncSession.execute at 0x7e749cd69e80>
                   -> <sqlalchemy.ext.asyncio.session.AsyncSession object at 0x7e745acd1d30>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/ext/asyncio/session.py", line 449, in execute
    result = await greenlet_spawn(
                   -> <function greenlet_spawn at 0x7e74a5268300>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 201, in greenlet_spawn
    result = context.throw(*sys.exc_info())
             |       |      |   -> <built-in function exc_info>
             |       |      -> <module 'sys' (built-in)>
             |       -> <method 'throw' of 'greenlet.greenlet' objects>
             -> <_AsyncIoGreenlet object at 0x7e749902ae80 (otid=0x7e74a520c330) dead>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/orm/session.py", line 2351, in execute
    return self._execute_internal(
           |    -> <function Session._execute_internal at 0x7e74a4366ae0>
           -> <sqlalchemy.orm.session.Session object at 0x7e745acd1fd0>
  File "/app/.venv/lib/python3.14/site-packages/sqlalchemy/orm/session.py", line 2249, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                   |      |                 -> <classmethod(<function AbstractORMCompileState.orm_execute_statement at 0x7e74a4384f60>)>
                   |      -> <class 'sqlalchemy.orm.context.ORMSelectCompileState'>
                   -> typing.Any
  File "/app/.venv/lib/python3.14/site-pack...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions