From 0cf931dd566653e2bc01a0577fb2853456125925 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Wed, 26 Aug 2026 09:56:48 -0700 Subject: [PATCH] fix(trino): resolve the mapped host port in get_connection_url() get_connection_url() returned the container-internal port (self.port, e.g. 8080) instead of the Docker-mapped host port, so the URL it built could never actually connect -- the existing test bypassed this method entirely, connecting via trino.dbapi.connect() with an explicitly resolved get_exposed_port() instead, so the bug went uncaught. Fixes the same way CockroachDBContainer/CrateDBContainer already do it via _create_connection_url(), and adds a test that actually exercises get_connection_url() via SQLAlchemy, matching the sibling cockroachdb/ cratedb tests' pattern. Fixes #1111 --- src/testcontainers/community/trino/__init__.py | 2 +- tests/community/trino/test_trino.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/testcontainers/community/trino/__init__.py b/src/testcontainers/community/trino/__init__.py index 9b2503d6e..ed0ca0a1f 100644 --- a/src/testcontainers/community/trino/__init__.py +++ b/src/testcontainers/community/trino/__init__.py @@ -38,7 +38,7 @@ def __init__( ) def get_connection_url(self): - return f"trino://{self.user}@{self.get_container_host_ip()}:{self.port}" + return f"trino://{self.user}@{self.get_container_host_ip()}:{self.get_exposed_port(self.port)}" def _configure(self): pass diff --git a/tests/community/trino/test_trino.py b/tests/community/trino/test_trino.py index 0d593fc58..7b686ae8f 100644 --- a/tests/community/trino/test_trino.py +++ b/tests/community/trino/test_trino.py @@ -1,3 +1,4 @@ +import sqlalchemy from trino.dbapi import connect from testcontainers.community.trino import TrinoContainer @@ -16,3 +17,12 @@ def test_docker_run_trino(): rows = cur.fetchall() assert rows[0][0] == "451" conn.close() + + +def test_get_connection_url(): + container = TrinoContainer("trinodb/trino:451") + with container as trino: + engine = sqlalchemy.create_engine(trino.get_connection_url()) + with engine.connect() as connection: + result = connection.execute(sqlalchemy.text("SELECT version()")) + assert result.fetchone()[0] == "451"