|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from collections.abc import Mapping |
4 | | -from typing import Any |
| 4 | +from typing import Any, cast |
5 | 5 |
|
6 | 6 | import xmltodict |
7 | 7 |
|
@@ -76,7 +76,7 @@ def untag(self, resource_id: int, tag: str) -> list[str]: |
76 | 76 | def _get_endpoint_name(self) -> str: |
77 | 77 | if self.resource_type == ResourceType.DATASET: |
78 | 78 | return "data" |
79 | | - return self.resource_type.name |
| 79 | + return cast("str", self.resource_type.value) |
80 | 80 |
|
81 | 81 | def _handle_delete_exception( |
82 | 82 | self, resource_type: str, exception: OpenMLServerException |
@@ -114,23 +114,23 @@ def _handle_delete_exception( |
114 | 114 | raise exception |
115 | 115 |
|
116 | 116 | def _extract_id_from_upload(self, parsed: Mapping[str, Any]) -> int: |
117 | | - # reads id from |
118 | | - # sample parsed dict: {"oml:openml": {"oml:upload_flow": {"oml:id": "42"}}} |
| 117 | + # reads id from upload response |
| 118 | + # actual parsed dict: {"oml:upload_flow": {"@xmlns:oml": "...", "oml:id": "42"}} |
119 | 119 |
|
120 | 120 | # xmltodict always gives exactly one root key |
121 | 121 | ((_, root_value),) = parsed.items() |
122 | 122 |
|
123 | 123 | if not isinstance(root_value, Mapping): |
124 | 124 | raise ValueError("Unexpected XML structure") |
125 | 125 |
|
126 | | - # upload node (e.g. oml:upload_task, oml:study_upload, ...) |
127 | | - ((_, upload_value),) = root_value.items() |
| 126 | + # Look for oml:id directly in the root value |
| 127 | + if "oml:id" in root_value: |
| 128 | + id_value = root_value["oml:id"] |
| 129 | + if isinstance(id_value, (str, int)): |
| 130 | + return int(id_value) |
128 | 131 |
|
129 | | - if not isinstance(upload_value, Mapping): |
130 | | - raise ValueError("Unexpected upload node structure") |
131 | | - |
132 | | - # ID is the only leaf value |
133 | | - for v in upload_value.values(): |
| 132 | + # Fallback: check all values for numeric/string IDs |
| 133 | + for v in root_value.values(): |
134 | 134 | if isinstance(v, (str, int)): |
135 | 135 | return int(v) |
136 | 136 |
|
|
0 commit comments