testcontainers / testcontainers/testcontainers-python

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

オープン 初心者向け
#1,111 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
2.3k
フォーク
386
平均マージ
4時間 40分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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 を短くまとめたダイジェスト。