Skip to content

POST /v1/statement requests missing charset in Content-Type header #600

@choseungyoon

Description

@choseungyoon

Describe the bug

When submitting queries via POST /v1/statement, the trino-python-client sends the request body with Content-Type: text/plain without a charset parameter. This causes issues with Trino Gateway's requestAnalyzerConfig feature, which requires the charset to be explicitly set in order to parse the SQL body for routing rule evaluation.

Expected behavior

The client should send Content-Type: text/plain; charset=utf-8 since the Trino client protocol uses UTF-8 encoded SQL strings.

Actual behavior

The client sends Content-Type: text/plain without charset, causing Trino Gateway to log:

DEBUG io.trino.gateway.ha.router.TrinoQueryProperties charset is not set in the request

And the Gateway fails to read the SQL body, resulting in empty catalogs, tables, and body fields in trinoQueryProperties. This breaks all SQL-aware routing rules.

Steps to reproduce

  1. Set up Trino Gateway with requestAnalyzerConfig.analyzeRequest: true
  2. Submit a query using trino-python-client:
from trino.dbapi import connect
 
conn = connect(
    host="gateway-host",
    port=38080,
    user="test",
)
cur = conn.cursor()
cur.execute("SELECT * FROM catalog.schema.table LIMIT 1")
  1. Observe that the Gateway cannot parse the SQL body

Workaround

Set the Content-Type header explicitly via a custom requests.Session:

import requests
 
http_session = requests.Session()
http_session.headers.update({
    "Content-Type": "text/plain; charset=utf-8"
})
 
conn = connect(
    host="gateway-host",
    port=38080,
    http_session=http_session,
    # ...
)

Log output

No response

Operating System

Redhat

Trino Python client version

0.337.0

Trino Server version

477

Python version

3.13.12

Additional context

Related Trino Gateway issue: trinodb/trino-gateway#1032

While the Gateway should ideally handle missing charset by defaulting to UTF-8, the client should also follow best practices by including the charset in the Content-Type header.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions