testcontainers / testcontainers/testcontainers-python

TrinoContainer.get_connection_url() returns the internal port, not the mapped host port

未关闭 适合新手
#1,111 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
2.3k
派生
386
平均合并
4 小时 40 分钟
30 天内合并 PR
1

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

定位 TrinoContainer 的实现,并阅读 get_connection_url()、get_exposed_port() 以及可比较的 CockroachDBContainer 或 CrateDBContainer URL 方法。为映射端口的 URL 行为添加覆盖,并验证通过 get_connection_url() 创建的连接能够访问正在运行的 Trino 容器。

由索引模型根据 Issue 内容生成。

评估

技术栈
docker, python, sqlalchemy
领域
databases, testing
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
活跃
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。