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
ORM from_statement().params() values lost when statement is compiled without cache key #13709
Originally reported in #13708. Regression from the new ExecutableStatement.params() implementation added in #7066 (see also #12915).
In 2.1, values passed to .params() on an ORM select().from_statement() construct are lost when the statement is compiled without a cache key, e.g. when the compiled cache is disabled via query_cache_size=0 / compiled_cache=None, or when the statement is stringified directly. This worked in 2.0.
importsqlalchemyassafromsqlalchemy.ormimportDeclarativeBase, Mapped, mapped_column, SessionclassBase(DeclarativeBase):
passclassTask(Base):
__tablename__="task"id: Mapped[int] =mapped_column(primary_key=True)
name: Mapped[str]
e=sa.create_engine("sqlite://", query_cache_size=0)
Base.metadata.create_all(e)
withSession(e) ass:
s.add(Task(id=1, name="a"))
s.commit()
stmt= (
sa.select(Task)
.from_statement(sa.text("select * from task where name = :n"))
.params(n="a")
)
print(stmt.compile().params) # {'n': None}, expected {'n': 'a'}# raises: A value is required for bind parameter 'n's.execute(stmt).scalars().all()
With the default compiled cache enabled the statement works, since the parameter values are carried in the cache key.
.params() on select(), text(), text().columns() and compound selects all work in this scenario; FromStatement is the only construct that does not register its own .params() with the compiler.
Workarounds: apply .params() to the text() construct itself, or pass the parameters to Session.execute().
Activity
sqla-tester commentedon Oct 21, 2026
Mike Bayer has proposed a fix for this issue in the main branch:
apply FromStatement params() when compiling without cache key https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/7098
apply FromStatement params() when compiling without cache key
test .params() for all statements with and without compiled cache