You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQLAlchemyTableRetriever: colons inside string literals are parsed as bind parameters #4278
Describe the bug SQLAlchemyTableRetriever wraps every query and every init_script statement in sqlalchemy.text(). text() treats :name as a bind parameter, even inside a quoted string literal, and the component never passes parameters. So valid SQL that has a colon followed by a word character inside a string fails.
To Reproduce
fromhaystack_integrations.components.retrievers.sqlalchemyimportSQLAlchemyTableRetrieverr=SQLAlchemyTableRetriever(drivername="sqlite", database=":memory:",
init_script=["CREATE TABLE t (id INT, body TEXT)"])
print(r.run(query="SELECT 1 WHERE 'see :ref' = 'see :ref'")["error"])
# (sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'ref'SQLAlchemyTableRetriever(drivername="sqlite", database=":memory:",
init_script=["CREATE TABLE t (b TEXT)", "INSERT INTO t VALUES ('{\"k\":1}')"]).warm_up()
# raises StatementError: A value is required for bind parameter '1'
Expected behavior
The SQL runs as written, the same as in sqlite3 / psql. JSON strings like '{"k":1}' and text such as 'see :ref' are common in seed data and in LLM-generated queries.
Additional context
Seen on main (5b1d6c1), SQLAlchemy 2.x, Python 3.14. A small fix is to escape colons before text() (\: is SQLAlchemy's documented escape), which keeps Postgres :: casts and % handling intact. I have a fix with a test ready and will open a PR.
Activity