Skip to content

Commit 04bc83b

Browse files
committed
fix: remove duplicate server name in cache path
identified in https://github.com/openml/openml-python/actions/runs/23148612114/job/67243650521?pr=1609
1 parent 44b48b5 commit 04bc83b

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

openml/_api/clients/http.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def get_key(self, url: str, params: dict[str, Any]) -> str:
5050
"""
5151
Generate a filesystem-safe cache key for a request.
5252
53-
The key is constructed from the reversed domain components, URL path
54-
segments, and URL-encoded query parameters (excluding ``api_key``).
53+
The key is constructed from URL path segments and
54+
URL-encoded query parameters (excluding ``api_key``).
5555
5656
Parameters
5757
----------
@@ -66,13 +66,12 @@ def get_key(self, url: str, params: dict[str, Any]) -> str:
6666
A relative path string representing the cache key.
6767
"""
6868
parsed_url = urlparse(url)
69-
netloc_parts = parsed_url.netloc.split(".")[::-1]
7069
path_parts = parsed_url.path.strip("/").split("/")
7170

7271
filtered_params = {k: v for k, v in params.items() if k != "api_key"}
7372
params_part = [urlencode(filtered_params)] if filtered_params else []
7473

75-
return str(Path(*netloc_parts, *path_parts, *params_part))
74+
return str(Path(*path_parts, *params_part))
7675

7776
def _key_to_path(self, key: str) -> Path:
7877
"""

tests/test_api/test_http.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,31 @@ def sample_download_url_v1(test_server_v1) -> str:
4242
def test_cache(cache, sample_url_v1):
4343
params = {"param1": "value1", "param2": "value2"}
4444

45+
# validate key
46+
4547
parsed_url = urlparse(sample_url_v1)
46-
netloc_parts = parsed_url.netloc.split(".")[::-1]
4748
path_parts = parsed_url.path.strip("/").split("/")
4849
params_key = "&".join([f"{k}={v}" for k, v in params.items()])
4950

50-
5151
key = cache.get_key(sample_url_v1, params)
5252

5353
expected_key = os.path.join(
54-
*netloc_parts,
5554
*path_parts,
5655
params_key,
5756
)
5857

5958
assert key == expected_key
6059

60+
# validate path
61+
62+
path = cache._key_to_path(key)
63+
expected_path = Path(openml.config.get_cache_directory()).joinpath(key)
64+
65+
assert path == expected_path
66+
assert ":" not in str(path)
67+
68+
# validate save/load
69+
6170
# mock response
6271
req = Request("GET", sample_url_v1).prepare()
6372
response = Response()

0 commit comments

Comments
 (0)