[Bug] Python Client IoTDBContainer and Example is not well behaved and IoTDBContainer will fail on Windows
- Ngôn ngữ chính
- Java
- Star
- 6.4k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 115
Mô tả
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/iotdb/issues) and found nothing similar.
### Version
Windows 11 22H2
IoTDB 1.1.0
### Describe the bug and provide the minimal reproduce step
In class `IoTDBContainer`:
```python
@wait_container_is_ready()
def _connect(self):
session = Session(
self.get_container_host_ip(), self.get_exposed_port(6667), "root", "root"
)
session.open(False)
session.close()
```
`get_exposed_port` return a `str`.
[Exampe](https://iotdb.apache.org/UserGuide/Master/API/Programming-Python-Native-API.html#how-to-use-example) use `str` port as well.
However, `TSocket` in `thrift` actually expect an `int` for `port`:
```python
class TSocket(TSocketBase):
"""Socket implementation of TTransport base."""
def __init__(self, host='localhost', port=9090, unix_socket=None,
socket_family=socket.AF_UNSPEC,
socket_keepalive=False):
"""Initialize a TSocket
@param host(str) The host to connect to.
@param port(int) The (TCP) port to connect to.
@param unix_socket(str) The filename of a unix socket to connect to.
(host and port will be ignored.)
@param socket_family(int) The socket family to use with this socket.
@param socket_keepalive(bool) enable TCP keepalive, default off.
"""
```
```python
@property
def _address(self):
return self._unix_socket if self._unix_socket else '%s:%d' % (self.host, self.port)
def open(self):
if self.handle:
raise TTransportException(type=TTransportException.ALREADY_OPEN, message="already open")
try:
addrs = self._resolveAddr()
except socket.gaierror as gai:
msg = 'failed to resolve sockaddr for ' + str(self._address)
...
```
Note the `%d` here. if the `self.port` is a `str`, when resolve address fail, an unrelated error will be raised:
```
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
... LONG stack trace
TypeError: %d format: a real number is required, not str
```
I omit stack trace here, but in fact the terminal filled with stack trace and the plausible TypeError distracted me from discover the real bug: `self.get_container_host_ip()` return `'localnpipe'`.
How to reproduce:
(on Windows)
```python
from iotdb.IoTDBContainer import IoTDBContainer
IoTDBContainer()
```
### What did you expect to see?
1. no `TypeError: %d format: a real number is required, not str` raised.
2. host should be `localhost` instead of `localnpipe`
this seems an upstream bug.
there is a workaround: set environment variable `TC_HOST='localhost'`
### What did you see instead?
`TypeError: %d format: a real number is required, not str` is raised.
IoTDBContainer use `localnpipe` instead of `localhost`.
### Anything else?
_No response_
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với IoTDBContainer._connect và ví dụ về native API của Python, sau đó chạy bản tái hiện IoTDBContainer() được cung cấp trên Windows. Xác minh rằng cổng được truyền cho Session là kiểu số, host không phải là localnpipe và TypeError không liên quan không còn che khuất các lỗi kết nối.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- databases
- 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
- 45/100