Visitar URL original
New params handling does not play nice with `compile()` with literal_binds=True · Issue #13635 · sqlalchemy/sqlalchemy · GitHub
Skip to content

New params handling does not play nice with compile() with literal_binds=True #13635

Closed

Description

@CaselIT

The change made in #7066 improved the behaviour of params in most sql construct.
This apparently caused a regression when using compile_kwargs={"literal_binds": True}

import sqlalchemy as sa

t = sa.Table(
    "t",
    sa.MetaData(),
    sa.Column("id", sa.Integer, primary_key=True),
    sa.Column("name", sa.String()),
)

s = sa.select(t).where(t.c.id == sa.bindparam("id"))
s2 = s.params(id=1)

e = sa.create_engine("sqlite:///:memory:")
t.metadata.create_all(e)
e.echo = True
with e.connect() as conn:
    result = conn.execute(s2).all()

c = s2.compile(dialect=e.dialect)
print(c.string, c.params)
c2 = s2.compile(dialect=e.dialect, compile_kwargs={"literal_binds": True})
print(c2.string, c2.params)

this prints

2026-10-02 16:17:52,112 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2026-10-02 16:17:52,112 INFO sqlalchemy.engine.Engine SELECT t.id, t.name
FROM t
WHERE t.id = ?
2026-10-02 16:17:52,112 INFO sqlalchemy.engine.Engine [generated in 0.00095s] (1,)
2026-10-02 16:17:52,113 INFO sqlalchemy.engine.Engine ROLLBACK
SELECT t.id, t.name
FROM t
WHERE t.id = ? {'id': 1}
path/to/file.py:21: SAWarning: Bound parameter 'id' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not' (this warning may be suppressed after 10 occurrences)
  c2 = s2.compile(dialect=e.dialect, compile_kwargs={"literal_binds": True})
SELECT t.id, t.name
FROM t
WHERE t.id = NULL {}

the param is lost when using literal binds

Activity

  1. added this to the 2.1.x milestone on Oct 2, 2026
  2. added
    regressionsomething worked and was broken by a change
    on Oct 2, 2026
  3. sqla-tester commented on Oct 2, 2026

    @sqla-tester
    Collaborator

    Mike Bayer has proposed a fix for this issue in the main branch:

    render statement params with literal_binds https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/7023

  4. added a commit that references this issue on Oct 5, 2026
    1b04136
  5. added a commit that references this issue on Oct 29, 2026
    d30a0a7
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

    bugSomething isn't workingregressionsomething worked and was broken by a changesql

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions