testcontainers / testcontainers/testcontainers-python
TrinoContainer.get_connection_url() returns the internal port, not the mapped host port
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 2.3k
- Fork
- 386
- Merge trung bình
- 4 giờ 40 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Xác định phần triển khai của TrinoContainer và đọc get_connection_url(), get_exposed_port() cũng như các phương thức URL tương ứng của CockroachDBContainer hoặc CrateDBContainer. Bổ sung coverage cho hành vi URL với cổng được ánh xạ và xác minh rằng một kết nối được tạo từ get_connection_url() có thể truy cập container Trino đang chạy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- docker, python, sqlalchemy
- Lĩnh vực
- databases, testing
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 78/100