testcontainers / testcontainers/testcontainers-python

MongoDbContainer on Windows 10 fails with getaddrinfo error

Đang mở
#99 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

👀 requires attention 📦 package: mongodb 🪟 windows
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ả

The following code fails with testcontainers-python 3.0.2:

from testcontainers.mongodb import MongoDbContainer
with MongoDbContainer('mongo:4.2.2') as mongo_:
...     db = mongo_.get_connection_client().test
...     db.test.insert_one({'foo': 'bar'})

with

Pulling image mongo:4.2.2
Container started:  d5ca66c443
Traceback (most recent call last):
  File "<input>", line 3, in <module>
  File "C:\...\venv\lib\site-packages\pymongo\collection.py", line 695, in insert_one
    self._insert(document,
  File "C:\...\venv\lib\site-packages\pymongo\collection.py", line 610, in _insert
    return self._insert_one(
  File "C:\...\venv\lib\site-packages\pymongo\collection.py", line 599, in _insert_one
    self.__database.client._retryable_write(
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1490, in _retryable_write
    with self._tmp_session(session) as s:
  File "C:\Program Files\Python38\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1823, in _tmp_session
    s = self._ensure_session(session)
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1810, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1763, in __start_session
    server_session = self._get_server_session()
  File "C:\...\venv\lib\site-packages\pymongo\mongo_client.py", line 1796, in _get_server_session
    return self._topology.get_server_session()
  File "C:\...\venv\lib\site-packages\pymongo\topology.py", line 482, in get_server_session
    self._select_servers_loop(
  File "C:\...\venv\lib\site-packages\pymongo\topology.py", line 208, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: localnpipe:32775: [Errno 11001] getaddrinfo failed

Interestingly, the MongoDbContainer.get_connection_url() method returns a URL with hostname localnpipe, which I suspect the mongo client does not understand. Using pymongo directly, I can connect to the created container using a hostname of localhost.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ MongoDbContainer.get_connection_url() và tái hiện ví dụ MongoDbContainer được nêu trên Windows 10, so sánh với kết nối PyMongo trực tiếp sử dụng localhost. Được xem là hoàn thành khi URL kết nối được trả về sử dụng một hostname mà PyMongo chấp nhận và thao tác insert thành công mà không có lỗi getaddrinfo.

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, mongodb, python
Lĩnh vực
databases, testing
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.