Skip to content

sqlite+aiosqlite implementation cannot open database file #4077

@agherasim

Description

@agherasim

Describe the bug
When referencing a sqlite database using the aiosqlite driver, the file cannot be loaded due to mixup between DB url and expected filesystem path for aiosqlite.connect method.

Using configuration sqlite+aiosqlite:///./sessions.db results in sqlite3.OperationalError: unable to open database file despite correct file path and permissions.

To Reproduce
Steps to reproduce the behavior:

  1. Install google-adk v1.21.0
  2. Configure DatabaseSessionService with url sqlite+aiosqlite:///./sessions.db
  3. Run a fastapi instance and request a new session
  4. Provide error or stacktrace
  File "/Users/<path_redacted>/.venv/lib/python3.13/site-packages/google/adk/sessions/sqlite_session_service.py", line 131, in create_session
    async with self._get_db_connection() as db:
               ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 214, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<path_redacted>/.venv/lib/python3.13/site-packages/google/adk/sessions/sqlite_session_service.py", line 418, in _get_db_connection
    async with aiosqlite.connect(self._db_path) as db:
               ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Users/<path_redacted>/.venv/lib/python3.13/site-packages/aiosqlite/core.py", line 154, in __aenter__
    return await self
           ^^^^^^^^^^
  File "/Users/<path_redacted>/.venv/lib/python3.13/site-packages/aiosqlite/core.py", line 141, in _connect
    self._connection = await future
                       ^^^^^^^^^^^^
  File "/Users/<path_redacted>/.venv/lib/python3.13/site-packages/aiosqlite/core.py", line 65, in _connection_worker_thread
    result = function()
  File "/Users/<path_redacted>/.venv/lib/python3.13/site-packages/aiosqlite/core.py", line 455, in connector
    return sqlite3.connect(loc, **kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file

Expected behavior
The DB file should be created (if missing) and a new session should be created and stored.

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): Python 3.13.0
  • ADK version(pip show google-adk): v1.21.0

Metadata

Metadata

Assignees

Labels

services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions