A percent sign in a statement reaches the server doubled
评估
这个 Issue 还没有评估数据。
描述
SQLAlchemy writes a percent sign in a statement as %% when the driver takes %(name)s parameters, and the driver is expected to send one %. crate-python takes these parameters since 2.2.0, but its cursor sends %% to the server unchanged. sqlalchemy-cratedb uses them since 0.43.0, so from that release a percent sign in a statement arrives doubled (0.42.0 returns the right results):
# docker run -d --rm --name crate -p 4200:4200 crate:6.5.1 -Cdiscovery.type=single-node
# uv run --with sqlalchemy-cratedb==0.45.0 python repro.py
import sqlalchemy as sa
e = sa.create_engine("crate://localhost:4200")
with e.connect() as c:
# expected 'a%', actual 'a%%'
print(c.execute(sa.text("SELECT 'a%'")).scalar())
# expected 1, actual ProgrammingError: ParsingException ... 'SELECT 7 %%'
try:
print(c.execute(sa.select(sa.literal_column("7") % sa.literal_column("3"))).scalar())
except Exception as ex:
print(type(ex).__name__, str(ex).splitlines()[0])
# expected 'a%b', actual 'a%%b'
print(c.execute(sa.text("SELECT 'a%' || :x"), {"x": "b"}).scalar())
In DDL, server_default="100%" stores 100%%, and a table with Computed("id % 3") cannot be created. A value passed as a parameter is not affected.
The cursor shows it without SQLAlchemy:
# crate-python returns 'a%%b', psycopg returns 'a%b'
cursor.execute("SELECT 'a%%' || %(x)s", {"x": "b"})
When execute or executemany gets parameters as a dict, the cursor needs to turn %% into %, as psycopg does (SQLAlchemy passes an empty dict for a statement without parameters). A call without parameters needs no change, because psycopg leaves %% as it is there too.
- 主要语言
- Python
- 星标
- 85
- 派生
- 37
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
crate/crate-python 的其他 Issue
-
[Security] tarfile.extractall without member validation in src/crate/testing/layer.py可能已有人在做 @theluckystrike 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
crate/crate-python#794 · 2 条评论 ·
-
cursor.description's type_code is always None, even though col_types is already available internally可能已有人在做 @rnovatorov 于 10 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 72/100
crate/crate-python#837 · 2 条评论 ·
-
NUMERIC reads: full digits arrive, the decode drops them可能已有人在做 @aminghadersohi 于 69 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 52/100
crate/crate-python#826 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 35/100
crate/crate-python#751 · 7 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
crate/crate-python#729 · 1 条评论 ·
查看 crate/crate-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
hugohe3/ppt-master#366 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 89/100
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
521xueweihan/HelloGitHub#4716 ·
-
难度 1/5 1 小时以内 新手友好度 84/100
pcqpcq/open-source-android-apps#619 ·
维护者通常 1 天内回复
-
contribution Windows 主机
难度 2/5 1-3 小时 新手友好度 72/100
Lee-xeo/Claude-Cage#1519 ·
维护者通常 1 天内回复