llamaIndex - ✅(Solved) Fix [Bug]: Specifying custom async_engine and db_schema in Memory.from_defaults causes db_schema to be ignored [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#20746Fetched 2026-04-08 00:31:14
View on GitHub
Comments
3
Participants
3
Timeline
8
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2referenced ×2closed ×1

Fix Action

Fix / Workaround

Workaround is to pass whatever to async_database_uri to fix it.

memory = Memory.from_defaults(
    session_id="chat_id",
    table_name="conversations",
    async_database_uri="fake placeholder",
    async_engine=my_async_engine,
    db_schema="llama",
)

PR fix notes

PR #20779: fix: respect db_schema when custom async_engine is provided

Description (problem / solution / changelog)

Description

Fixes #20746

When a custom async_engine is passed to SQLAlchemyChatStore (or via Memory.from_defaults) without an explicit async_database_uri, the URI defaults to sqlite+aiosqlite:///:memory:. This caused _is_sqlite_database() to incorrectly return True even for non-SQLite engines like PostgreSQL, silently ignoring the db_schema parameter.

Root Cause

In __init__, the line async_database_uri=async_database_uri or DEFAULT_ASYNC_DATABASE_URI forces the URI to a SQLite default when None is passed. Then _is_sqlite_database() checks only self.async_database_uri, which is the SQLite default - not the actual engine's database type.

Fix

Updated _is_sqlite_database() to check the actual engine URL (self._async_engine.url) when a custom engine is provided, falling back to self.async_database_uri when no engine exists. This is a 2-line change with no impact on existing behavior when engines are not explicitly provided.

Tests

Added 4 new test cases to test_sql_schema.py:

  • test_is_sqlite_database_with_custom_engine - verifies PostgreSQL engine is not detected as SQLite
  • test_is_sqlite_database_with_sqlite_engine - verifies actual SQLite engine is still correctly detected
  • test_is_sqlite_database_without_engine - verifies URI fallback works as before
  • test_custom_engine_with_schema_creates_schema - end-to-end test verifying schema creation SQL is executed when custom engine is provided

All 20 existing tests pass with zero regressions.

Changed files

  • llama-index-core/llama_index/core/storage/chat_store/sql.py (modified, +2/-0)
  • llama-index-core/tests/storage/chat_store/test_sql_schema.py (modified, +82/-0)

Code Example

memory = Memory.from_defaults(
    session_id="chat_id",
    table_name="conversations",
    async_database_uri="fake placeholder",
    async_engine=my_async_engine,
    db_schema="llama",
)

---

memory = Memory.from_defaults(
    session_id="chat_id",
    table_name="conversations",
    async_engine=my_async_engine,
    db_schema="llama",
)

---
RAW_BUFFERClick to expand / collapse

Bug Description

In SQLAlchemyChatStore's _setup_tables function, it ignores the db_schema value if it checks is_sqlite_database() to be true. This function checks if the async_database_uri starts with "sqlite".

However, if a async_engine is passed instead of async_database_uri, the default value does start with "sqlite". This causes the db_schema to be ignored.

Workaround is to pass whatever to async_database_uri to fix it.

memory = Memory.from_defaults(
    session_id="chat_id",
    table_name="conversations",
    async_database_uri="fake placeholder",
    async_engine=my_async_engine,
    db_schema="llama",
)

Related PR: !19741

Version

0.14.10

Steps to Reproduce

Create Memory passing both db_schema and async_engine, without passing in async_database_uri

memory = Memory.from_defaults(
    session_id="chat_id",
    table_name="conversations",
    async_engine=my_async_engine,
    db_schema="llama",
)

Relevant Logs/Tracbacks

extent analysis

<think> Okay, let's see. The user is reporting an issue with SQLAlchemyChatStore's _setup_tables function. The problem is that when using an async_engine instead of async_database_uri, the db_schema is ignored because the code checks if the URI starts with "sqlite". But when the engine is provided, the default URI is "sqlite", so the check passes and the schema isn't applied.

Hmm, the root cause here is that the code checks the async_database_uri to determine if it's SQLite. But if the engine is provided instead, the default URI is set to "sqlite", which triggers the check, even though the actual database might not be SQLite. That's why the db_schema is ignored.

So the fix should involve checking the actual engine's dialect instead of relying on the URI. Because the engine's dialect would correctly identify if it's SQLite, regardless of the URI provided. That way, even if the URI is a placeholder, the check against the engine's dialect would be accurate.

The solution would be to modify the _setup_tables function to check the engine's dialect. For example, using engine.dialect.driver to see if it's SQLite. Then, only skip the schema if it's truly SQLite. That way, when using an async_engine, the check is accurate.

Let me outline the steps. First, in the _setup_tables function, instead of checking if the URI starts with "sqlite", we should check the engine's dialect. So replace the URI check with something like engine.dialect.driver == "sqlite".

Also, need to make sure that when the engine is provided, the code uses that engine's dialect. That would correctly identify the database type. Then, the db_schema would be applied unless it's actually SQLite.

So the code change would involve modifying the condition in _setup_tables. For example, instead of:

if is_sqlite_database():

Which checks the URI, we should check the engine's dialect. So maybe:

if engine.d

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

llamaIndex - ✅(Solved) Fix [Bug]: Specifying custom async_engine and db_schema in Memory.from_defaults causes db_schema to be ignored [1 pull requests, 3 comments, 3 participants]