Skip to content

enable_fts() exhausts iterator columns before populating the index #902

Open

Description

@er-s-an

Problem

Table.enable_fts() accepts columns: Iterable[str], but passing a one-shot iterator raises sqlite3.OperationalError: near ")": syntax error. The same columns supplied as a list work. The FTS virtual table has already been created when the error occurs, so a retry without replace=True also encounters an existing table.

Reproduced locally against main 9c66bafa52ae23d40499c74b0db3b635bcddb876, Python 3.12.14, using an in-memory database:

from sqlite_utils import Database

db = Database(memory=True)
table = db["notes"].insert({"text": "hello"})
table.enable_fts(iter(["text"]))
# sqlite3.OperationalError: near ")": syntax error

Replacing iter(["text"]) with ["text"] succeeds and list(table.search("hello")) returns the record. I reproduced the failure with both FTS4 and FTS5, with and without create_triggers=True.

The iterable is consumed while building CREATE VIRTUAL TABLE, then passed to populate_fts(). Trigger construction also reuses it. Materializing the columns once would preserve the declared iterable contract.

AI assistance: OpenAI Codex inspected the code and ran this reproduction. No live service, user database, or external model call was used.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions