TrinoContainer.get_connection_url() returns the internal port, not the mapped host port
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Locate the TrinoContainer implementation and read get_connection_url(), get_exposed_port(), and the comparable CockroachDBContainer or CrateDBContainer URL methods. Add coverage for the mapped-port URL behavior and verify that a connection created from get_connection_url() reaches the running Trino container.
Written by the indexing model from the issue text.
Description
TrinoContainer.get_connection_url() builds the URL as trino://{user}@{host}:{self.port}, and self.port is the fixed container-internal port set in __init__ (8080 by default). It's never resolved through get_exposed_port(). Since Docker maps that to a random host port, the URL this method returns can't actually connect to anything.
Repro (4.15.0):
from testcontainers.community.trino import TrinoContainer
from sqlalchemy import create_engine, text
with TrinoContainer() as trino:
print(trino.port) # 8080
print(trino.get_exposed_port(trino.port)) # the real mapped port, e.g. 58092
print(trino.get_connection_url()) # trino://test@localhost:8080 - wrong
engine = create_engine(trino.get_connection_url())
with engine.connect() as conn:
conn.execute(text("select 1")) # ConnectionRefusedError / TrinoConnectionError
Building the URL manually with get_exposed_port() instead of self.port connects fine.
For comparison, CockroachDBContainer/CrateDBContainer don't have this problem since they route through _create_connection_url(), which does resolve the exposed port. Looks like an isolated miss in the Trino module rather than a pattern elsewhere.
Suggested fix, matching how the other modules do it:
def get_connection_url(self):
return f"trino://{self.user}@{self.get_container_host_ip()}:{self.get_exposed_port(self.port)}"
Happy to open a PR with this if useful. Found it while wiring up a nightly testcontainers job for apache/superset's db engine spec tests.
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 386
- Avg merge
- 4h 40m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from testcontainers/testcontainers-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
testcontainers/testcontainers-python#1115 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
testcontainers/testcontainers-python#1086 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
testcontainers/testcontainers-python#578 · 5 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Bug: Failure to connect to Reaper leaves stale ryuk containers, leading to container name collisions Open
Difficulty 3/5 1-2 days Newbie friendliness 72/100
testcontainers/testcontainers-python#1093 · 1 comment · 1 reaction ·
All issues in testcontainers/testcontainers-python
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100