Skip to content

Infinite version request loop (FastAPI with SQLAlchemy hitting a Trino docker desktop container) #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
jonroquet2 opened this issue May 21, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@jonroquet2
Copy link

jonroquet2 commented May 21, 2025

Expected behavior

  1. Web application starts
  2. Post request to application causes a connection to local trino server
  3. Connection makes a simple query (select * from tpch.sf1.nation) using sqlalchemy
  4. Data rows returned and logged

Code:
`

engine = create_engine("trino://jon@localhost:8080/system")
conn = engine.connect()

result = conn.execute(text("select 1 as x")).fetchall()
for row in result:
    logger.debug(row)

`

Actual behavior

Infinite loop of code requests calling "select version()" hit the local trino server, and python goes into an infinite loop:

(Note, this is one of several thousand, this never stops)

INFO 2025-05-21 15:58:51,240 trino.client 1013 - failed after 1 attempts
DEBUG 2025-05-21 15:58:51,243 urllib3.connectionpool 241 - Starting new HTTP connection (1269): localhost:8080
DEBUG 2025-05-21 15:58:51,255 urllib3.connectionpool 544 - http://localhost:8080 "POST /v1/statement HTTP/1.1" 200 351
DEBUG 2025-05-21 15:58:51,261 urllib3.connectionpool 544 - http://localhost:8080 "GET /v1/statement/queued/20250521_205902_04901_q83nv/ya189522748922861480aa59bd1ca7af2d04dc2fc/1 HTTP/1.1" 200 351
DEBUG 2025-05-21 15:58:51,268 urllib3.connectionpool 544 - http://localhost:8080 "GET /v1/statement/queued/20250521_205902_04901_q83nv/yae1ef533103b0d4dfe33f7c45c07325f4aa00b79/2 HTTP/1.1" 200 359
DEBUG 2025-05-21 15:58:51,276 urllib3.connectionpool 544 - http://localhost:8080 "GET /v1/statement/executing/20250521_205902_04901_q83nv/y201189cbc98d1a1f97104f718b9c6372baf9e43f/0 HTTP/1.1" 200 558
DEBUG 2025-05-21 15:58:51,284 urllib3.connectionpool 544 - http://localhost:8080 "GET /v1/statement/executing/20250521_205902_04901_q83nv/ya857eae45b999e5c9ab9fa64ff14b3a9e8a736a7/1 HTTP/1.1" 200 479

Steps To Reproduce

DBMS: Run a local docker container using trinodb/trino:latest
OS: WIndows 11
Python App: Python 3.10 or 3.12 (attempted using both)
Python Libraries:
trino==0.334.0
sqlalchemy==2.0.38

Using the above code, attempt to call your local docker trino. Any query fails - it never gets to the actual query.

Log output

The issue is the select version call in dialect.py:
def _get_server_version_info(cls, connection: Connection) -> Any: def get_server_version_info(_): query = "SELECT version()" try: res = connection.execute(sql.text(query)) version = res.scalar() return tuple([version]) except exc.ProgrammingError as e: logger.debug(f"Failed to get server version: {e.orig.message}") return None

When I replace this with "return 475", all behavior is now as expected.

Operating System

Windows 11

Trino Python client version

0.334.0

Trino Server version

475

Python version

3.12.9

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@hashhar hashhar added the bug Something isn't working label May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants