Skip to content

fix(core): honor configured schema when inserting SQL rows - #23666

Open
tteok1 wants to merge 1 commit into
run-llama:mainfrom
tteok1:contrib/sql-insert-configured-schema
Open

tteok1 wants to merge 1 commit into
run-llama:mainfrom
tteok1:contrib/sql-insert-configured-schema

Conversation

@tteok1

@tteok1 tteok1 commented Oct 23, 2026

Copy link
Copy Markdown

Description

SQLDatabase.insert_into_table("records", ...) raises KeyError when SQLDatabase has a configured schema: SQLAlchemy reflects the table under a key such as analytics.records, but insertion looks up records.

Resolve the schema-qualified metadata key first, while retaining exact-key lookup for callers already passing qualified names. This is a self-discovered bug; no existing issue is being claimed.

New Package?

  • Yes
  • No

Version Bump?

Not applicable to llama-index-core.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added unit tests covering this change.
  • Five SQLite cases cover the default schema, an explicitly selected default schema, an attached schema, and existing qualified-name calls. Each verifies that only the intended same-named table receives the row.
  • Before the fix: 2 failed, 3 passed. After the fix: all 5 passed.
  • SQL wrapper and structured SQL index tests: 32 passed, including the 5 new cases; one event-loop deprecation warning was emitted.
  • Core Mypy: no issues in 479 source files.
  • Repository pre-commit checks on both changed files and git diff --check: passed.

Validation used Windows/Python 3.12 and in-memory SQLite; no external database or model API was used.

AI assistance

AI assisted with identifying the bug, implementing the metadata lookup, and writing regression tests. The checks above were run locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant