Skip to content

Commit 3d70dbd

Browse files
authored
fix: url attribute type validation (influxdata#672)
1 parent 70ce8cb commit 3d70dbd

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 1.47.0 [unreleased]
22

3+
### Bug Fixes
4+
1. [#672](https://github.com/influxdata/influxdb-client-python/pull/672): Adding type validation to url attribute in client object
5+
36
## 1.46.0 [2024-09-13]
47

58
### Bug Fixes

influxdb_client/client/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
5353
self.default_tags = default_tags
5454

5555
self.conf = _Configuration()
56+
if not isinstance(self.url, str):
57+
raise ValueError('"url" attribute is not str instance')
5658
if self.url.endswith("/"):
5759
self.conf.host = self.url[:-1]
5860
else:

tests/test_InfluxDBClient.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,35 @@ def test_version(self):
323323
version = self.client.version()
324324
self.assertTrue(len(version) > 0)
325325

326+
def test_url_attribute(self):
327+
# Wrong URL attribute
328+
wrong_types = [
329+
None,
330+
True, False,
331+
123, 123.5,
332+
dict({"url" : "http://localhost:8086"}),
333+
list(["http://localhost:8086"]),
334+
tuple(("http://localhost:8086"))
335+
]
336+
correct_types = [
337+
"http://localhost:8086"
338+
]
339+
for url_type in wrong_types:
340+
try:
341+
client_not_running = InfluxDBClient(url=url_type, token="my-token", debug=True)
342+
status = True
343+
except ValueError as e:
344+
status = False
345+
self.assertFalse(status)
346+
for url_type in correct_types:
347+
try:
348+
client_not_running = InfluxDBClient(url=url_type, token="my-token", debug=True)
349+
status = True
350+
except ValueError as e:
351+
status = False
352+
self.assertTrue(status)
353+
354+
326355
def test_build(self):
327356
build = self.client.build()
328357
self.assertEqual('oss', build.lower())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy