-
-
Notifications
You must be signed in to change notification settings - Fork 272
[ENH] V1 -> V2 Migration : Runs #1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5762185
3da4760
021a1e1
4c4a12c
1d91220
3e26ace
0060b2e
65ba66b
317c6e9
503ab82
e5b7af4
fd7ea2b
fa3cd40
716667c
68a403a
7e9bc1f
c603383
ff6a8b0
f01898f
5c4511e
9d0098f
43276d2
1206f69
bde5942
4948e99
a354167
1fe7e3e
54a3151
2b6fe65
29fd985
fa53f8d
2b2db96
0135ba2
c9617f9
5bc37b8
08d9916
37a468f
8caba11
a70a33f
d08b1fe
aaf9d4b
84d43a9
761ef9e
cf37a75
2eb7c7a
d9476c8
f4718c1
4560b6b
1913c10
7681949
01840a5
26ed4c1
c588d0c
b6ff720
80d5afc
f47112c
d44cf3e
ea7dda1
f0e5947
edcd006
cde0aae
48fa391
aa1e560
06b8497
384da91
1878138
dc26e01
e2d059b
d156ad4
d7a3788
b5b9ef6
68820fe
567eca4
ff33d8e
20ee072
0a7dd16
b2287c3
b7e285e
fd43c48
f4aab6b
d43cf86
3e323ed
9195fa6
5342eec
adc0e74
bfb2d3e
cabaecf
e14532f
a64203d
85c1113
39bf86a
7b66677
d2224c4
c6351e0
9608c36
f6bc7f7
baa3a38
d6146aa
b349581
52b93fe
ec9477f
ad05cd3
5cdc0ad
7457f16
f199479
282c7d9
10d134a
935f0f4
9514df8
53bee94
4f8c9b3
7f98c61
33b4ca0
a6b9a45
f924b32
541b0f2
acb173f
3e8d1f0
f83bdb5
2a42712
001caad
fb38a2d
03c4ca9
8d708fd
4f75bba
164f66f
c4dae43
36c20a2
ab3c1eb
0577e45
d4965eb
ea3a8ae
5d229c7
2a488ca
599c7e1
2867862
f09f3cd
5f731ce
bad7842
aefdb38
0f40b02
7ac1672
6ac1dfe
62924c9
27696bb
190face
95daaa6
7841ea8
cc515aa
e6a92df
1b8c22a
fc839a6
1c922af
ffa9ce9
a7b2d21
27fe790
8965112
72ea1a4
a696c49
755636d
d07af34
2d9c8ec
002b989
045d896
c437966
e27470a
d04d956
9263f7f
79dea29
f6497c2
dce7f54
40dd460
0fc917c
3d86b18
aba3d3e
d99d54d
dc22e3a
7318573
29ef187
cf94c89
298fbda
9870502
33065c2
76b92bb
419edcb
cb6d937
8544c8a
d4c413b
fab1a15
49789a7
8b07a20
276324a
73f7594
2ee7fa3
070731d
4be5bbd
9027c01
e5461a9
7d899a9
8587414
23a3450
ac28f82
4f6e7ec
176002c
0178ee0
4a66245
c762fb4
77c21f2
eac24fc
2ed65fe
f3b07de
29db3f1
3b4e538
8ac886b
305f4f0
b2bf164
e97e6c2
c66d73c
aa54e8e
2d452d3
c235812
39eb823
50eed37
7a000eb
79f6187
ec2b09a
b1a9e7f
d716ecf
3c29e71
b4ff0b2
93155ee
d3cc9a7
a6b82f4
3419973
8de99b7
4a24b83
7d61107
1ecbbba
65472ed
44b48b5
04bc83b
f926092
aa91d92
22d7179
dc081ca
808bc5b
61816f4
c02e09b
19c7dab
fe8f66b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,60 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from enum import Enum | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class RetryPolicy(str, Enum): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HUMAN = "human" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ROBOT = "robot" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class APIConfig: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base_url: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: int = 10 # seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class APISettings: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v1: APIConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v2: APIConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ConnectionConfig: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| retries: int = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| retry_policy: RetryPolicy = RetryPolicy.HUMAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class CacheConfig: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir: str = "~/.openml/cache" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ttl: int = 60 * 60 * 24 * 7 # one week | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Settings: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api: APISettings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| connection: ConnectionConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cache: CacheConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| settings = Settings( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api=APISettings( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v1=APIConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server="https://test.openml.org/", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base_url="api/v1/xml/", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key="normaluser", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v2=APIConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server="http://127.0.0.1:8001/", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base_url="", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key="...", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| connection=ConnectionConfig(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cache=CacheConfig(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+60
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | |
| from enum import Enum | |
| class RetryPolicy(str, Enum): | |
| HUMAN = "human" | |
| ROBOT = "robot" | |
| @dataclass | |
| class APIConfig: | |
| server: str | |
| base_url: str | |
| api_key: str | |
| timeout: int = 10 # seconds | |
| @dataclass | |
| class APISettings: | |
| v1: APIConfig | |
| v2: APIConfig | |
| @dataclass | |
| class ConnectionConfig: | |
| retries: int = 3 | |
| retry_policy: RetryPolicy = RetryPolicy.HUMAN | |
| @dataclass | |
| class CacheConfig: | |
| dir: str = "~/.openml/cache" | |
| ttl: int = 60 * 60 * 24 * 7 # one week | |
| @dataclass | |
| class Settings: | |
| api: APISettings | |
| connection: ConnectionConfig | |
| cache: CacheConfig | |
| settings = Settings( | |
| api=APISettings( | |
| v1=APIConfig( | |
| server="https://test.openml.org/", | |
| base_url="api/v1/xml/", | |
| api_key="normaluser", | |
| ), | |
| v2=APIConfig( | |
| server="http://127.0.0.1:8001/", | |
| base_url="", | |
| api_key="...", | |
| ), | |
| ), | |
| connection=ConnectionConfig(), | |
| cache=CacheConfig(), | |
| ) | |
| """ | |
| Backwards-compatible configuration module. | |
| This module re-exports the canonical configuration types and instances | |
| from :mod:`openml._api.setup.config` and the :class:`RetryPolicy` enum | |
| from :mod:`openml.enums` to avoid maintaining duplicate definitions. | |
| """ | |
| from openml.enums import RetryPolicy | |
| from openml._api.setup.config import ( | |
| APIConfig, | |
| APISettings, | |
| CacheConfig, | |
| ConnectionConfig, | |
| Settings, | |
| settings, | |
| ) | |
| __all__ = [ | |
| "RetryPolicy", | |
| "APIConfig", | |
| "APISettings", | |
| "ConnectionConfig", | |
| "CacheConfig", | |
| "Settings", | |
| "settings", | |
| ] |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merge was not clean here, right? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| from collections.abc import Mapping | ||
| from typing import Any, cast | ||
| from xml.parsers.expat import ExpatError | ||
|
|
||
| import xmltodict | ||
|
|
||
|
|
@@ -71,7 +72,7 @@ def publish(self, path: str, files: Mapping[str, Any] | None) -> int: | |
| If the server returns an error during upload. | ||
| """ | ||
| response = self._http.post(path, files=files) | ||
| parsed_response = xmltodict.parse(response.content) | ||
| parsed_response = self._parse_xml_response(response.content) | ||
| return self._extract_id_from_upload(parsed_response) | ||
|
|
||
| def delete(self, resource_id: int) -> bool: | ||
|
|
@@ -106,7 +107,7 @@ def delete(self, resource_id: int) -> bool: | |
| path = f"{endpoint_name}/{resource_id}" | ||
| try: | ||
| response = self._http.delete(path) | ||
| result = xmltodict.parse(response.content) | ||
| result = self._parse_xml_response(response.content) | ||
| return f"oml:{endpoint_name}_delete" in result | ||
| except OpenMLServerException as e: | ||
| self._handle_delete_exception(endpoint_name, e) | ||
|
|
@@ -143,7 +144,7 @@ def tag(self, resource_id: int, tag: str) -> list[str]: | |
| data = {f"{endpoint_name}_id": resource_id, "tag": tag} | ||
| response = self._http.post(path, data=data) | ||
|
|
||
| parsed_response = xmltodict.parse(response.content, force_list={"oml:tag"}) | ||
| parsed_response = self._parse_xml_response(response.content, force_list={"oml:tag"}) | ||
| result = parsed_response[f"oml:{endpoint_name}_tag"] | ||
| tags: list[str] = result.get("oml:tag", []) | ||
|
|
||
|
|
@@ -180,12 +181,28 @@ def untag(self, resource_id: int, tag: str) -> list[str]: | |
| data = {f"{endpoint_name}_id": resource_id, "tag": tag} | ||
| response = self._http.post(path, data=data) | ||
|
|
||
| parsed_response = xmltodict.parse(response.content, force_list={"oml:tag"}) | ||
| parsed_response = self._parse_xml_response(response.content, force_list={"oml:tag"}) | ||
| result = parsed_response[f"oml:{endpoint_name}_untag"] | ||
| tags: list[str] = result.get("oml:tag", []) | ||
|
|
||
| return tags | ||
|
|
||
| def _parse_xml_response(self, payload: bytes | str, **kwargs: Any) -> Mapping[str, Any]: | ||
| try: | ||
| return cast("Mapping[str, Any]", xmltodict.parse(payload, **kwargs)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this casting really needed? I don't think so |
||
| except ExpatError: | ||
| payload_text = ( | ||
| payload.decode("utf-8", errors="ignore") if isinstance(payload, bytes) else payload | ||
| ) | ||
| xml_start = payload_text.find("<?xml") | ||
| if xml_start == -1: | ||
| xml_start = payload_text.find("<oml:") | ||
| if xml_start == -1: | ||
| raise | ||
|
|
||
| xml_text = payload_text[xml_start:] | ||
| return cast("Mapping[str, Any]", xmltodict.parse(xml_text, **kwargs)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
|
||
| def _get_endpoint_name(self) -> str: | ||
| if self.resource_type == ResourceType.DATASET: | ||
| return "data" | ||
|
|
@@ -220,18 +237,23 @@ def _extract_id_from_upload(self, parsed: Mapping[str, Any]) -> int: | |
| if not isinstance(root_value, Mapping): | ||
| raise ValueError("Unexpected XML structure") | ||
|
|
||
| # Look for oml:id directly in the root value | ||
| if "oml:id" in root_value: | ||
| id_value = root_value["oml:id"] | ||
| if isinstance(id_value, (str, int)): | ||
| return int(id_value) | ||
| # 1. Specifically look for keys ending in _id or id (e.g., oml:id, oml:run_id) | ||
| for k, v in root_value.items(): | ||
| if ( | ||
| (k.endswith(("id", "_id")) or "id" in k.lower()) | ||
| and isinstance(v, (str, int)) | ||
| and str(v).isdigit() | ||
| ): | ||
| return int(v) | ||
|
|
||
| # Fallback: check all values for numeric/string IDs | ||
| # 2. Fallback: check all values for numeric/string IDs, excluding xmlns or URLs | ||
| for v in root_value.values(): | ||
| if isinstance(v, (str, int)): | ||
| return int(v) | ||
| val_str = str(v) | ||
| if val_str.isdigit(): | ||
| return int(val_str) | ||
|
|
||
| raise ValueError("No ID found in upload response") | ||
| raise ValueError(f"No ID found in upload response: {root_value}") | ||
|
|
||
|
|
||
| class ResourceV2API(ResourceAPI): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file