fix: support ipv6 - #234
Conversation
There was a problem hiding this comment.
Pull request overview
Adds IPv6 URL support to InfluxDBClient3 host parsing so that generated REST base_url and gRPC connection_string preserve IPv6 bracket formatting, with accompanying unit tests to validate behavior.
Changes:
- Update host parsing to re-wrap IPv6 hostnames in
[]when the input URL netloc indicates an IPv6 literal. - Add tests covering URL parsing for IPv4/hostname and IPv6 (including ports, paths, and queries).
- Add tests asserting the gRPC connection string generated for IPv6 hosts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
influxdb_client_3/__init__.py |
Adjusts host parsing to preserve IPv6 bracket formatting when constructing base_url / gRPC connection strings. |
tests/test_influxdb_client_3.py |
Adds unit tests validating parsed base_url and gRPC connection strings for IPv6 hosts. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #234 +/- ##
==========================================
+ Coverage 86.88% 86.90% +0.01%
==========================================
Files 28 28
Lines 2082 2084 +2
==========================================
+ Hits 1809 1811 +2
Misses 273 273 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c34f860 to
a2f786b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
influxdb_client_3/init.py:311
- The docstring now states IPv6 Zone IDs are not supported, but the constructor currently accepts hosts containing a zone id (e.g.
http://[fe80::1%25eth0]:8086) and will pass the percent-encoded value through intobase_url/gRPC connection strings. This is likely to fail later in Arrow Flight with a hard-to-diagnose error; consider rejecting zone IDs early with a clearValueErrorto match the documented contract.
# Parse the host input
parsed_url = urllib.parse.urlparse(host)
hostname = parsed_url.hostname if parsed_url.hostname else host
if "[" in parsed_url.netloc and "]" in parsed_url.netloc:
hostname = f"[{hostname}]"
tests/test_influxdb_client_3.py:84
- Tests cover bracket-wrapped IPv6 literals, but there is no assertion that IPv6 Zone IDs are rejected even though the PR description and docstrings state they are unsupported. Adding a zone-id case here would prevent accidental regression where a zone id silently flows into the gRPC connection string and fails later in Arrow Flight.
def test_parse_addresses(self):
tests = [
{"url": "http://192.168.0.5/db", "expect": "http://192.168.0.5:443"},
{"url": "http://192.168.0.1:80", "expect": "http://192.168.0.1:80"},
{"url": "https://[2001:db8::1]", "expect": "https://[2001:db8::1]:443"},
{"url": "https://[2001:db8::1]:8086/influx", "expect": "https://[2001:db8::1]:8086"},
{"url": "http://[2001:db8::1]:15000?token=my-token", "expect": "http://[2001:db8::1]:15000"},
{"url": "http://[2001:db8::1]", "expect": "http://[2001:db8::1]:443"},
{"url": "http://[2001:db8:a0b:12f0::1]:80", "expect": "http://[2001:db8:a0b:12f0::1]:80"},
{"url": "http://example.com", "expect": "http://example.com:443"},
{"url": "http://example.com:3000", "expect": "http://example.com:3000"},
]
for test in tests:
client = InfluxDBClient3(
host=test["url"],
org="my_org",
database="my_db",
token="my_token",
)
self.assertEqual(client.base_url, test["expect"])
Closes #
Proposed Changes
Checklist