A percent sign in a statement reaches the server doubled

Đang mở
#853 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@florinutz đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #854 của @florinutz — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

bug

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.

Ngôn ngữ chính
Python
Star
85
Fork
37
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của crate/crate-python

Tất cả issue của crate/crate-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.