Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit acb897a

Browse files
authored
deprecate request UID in favour of ID (#15)
1 parent 065aecf commit acb897a

File tree

6 files changed

+67
-39
lines changed

6 files changed

+67
-39
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Retrieve data:
9090
'tmp1-era5.grib'
9191

9292
>>> remote = client.submit(collection_id, request) # doesn't block
93-
>>> remote.request_uid
93+
>>> remote.request_id
9494
'...'
9595
>>> remote.status
9696
'...'
@@ -102,7 +102,7 @@ Retrieve data:
102102
Interact with a previously submitted job:
103103

104104
```python
105-
>>> remote = client.get_remote(remote.request_uid)
105+
>>> remote = client.get_remote(remote.request_id)
106106
>>> remote.delete()
107107
{...}
108108

datapi/api_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ def check_authentication(self) -> dict[str, Any]:
181181
"""
182182
return self._profile_api.check_authentication()
183183

184-
def download_results(self, request_uid: str, target: str | None = None) -> str:
184+
def download_results(self, request_id: str, target: str | None = None) -> str:
185185
"""Download the results of a request.
186186
187187
Parameters
188188
----------
189-
request_uid: str
190-
Request UID.
189+
request_id: str
190+
Request ID.
191191
target: str or None
192192
Target path. If None, download to the working directory.
193193
@@ -196,7 +196,7 @@ def download_results(self, request_uid: str, target: str | None = None) -> str:
196196
str
197197
Path to the retrieved file.
198198
"""
199-
return self.get_remote(request_uid).download(target)
199+
return self.get_remote(request_id).download(target)
200200

201201
def estimate_costs(self, collection_id: str, request: Any) -> dict[str, Any]:
202202
"""Estimate costs of the parameters in a request.
@@ -321,35 +321,35 @@ def get_processes(
321321
}
322322
return self._retrieve_api.get_processes(**params)
323323

324-
def get_remote(self, request_uid: str) -> datapi.Remote:
324+
def get_remote(self, request_id: str) -> datapi.Remote:
325325
"""
326326
Retrieve the remote object of a request.
327327
328328
Parameters
329329
----------
330-
request_uid: str
331-
Request UID.
330+
request_id: str
331+
Request ID.
332332
333333
Returns
334334
-------
335335
datapi.Remote
336336
"""
337-
return self._retrieve_api.get_job(request_uid).make_remote()
337+
return self._retrieve_api.get_job(request_id).make_remote()
338338

339-
def get_results(self, request_uid: str) -> datapi.Results:
339+
def get_results(self, request_id: str) -> datapi.Results:
340340
"""
341341
Retrieve the results of a request.
342342
343343
Parameters
344344
----------
345-
request_uid: str
346-
Request UID.
345+
request_id: str
346+
Request ID.
347347
348348
Returns
349349
-------
350350
datapi.Results
351351
"""
352-
return self.get_remote(request_uid).make_results()
352+
return self.get_remote(request_id).make_results()
353353

354354
def retrieve(
355355
self,

datapi/processing.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class Remote:
384384
def __attrs_post_init__(self) -> None:
385385
self.log_start_time = None
386386
self.last_status = None
387-
self.info(f"Request ID is {self.request_uid}")
387+
self.info(f"Request ID is {self.request_id}")
388388

389389
@property
390390
def _request_kwargs(self) -> RequestKwargs:
@@ -411,10 +411,20 @@ def _get_api_response(self, method: str, **kwargs: Any) -> ApiResponse:
411411
)
412412

413413
@property
414-
def request_uid(self) -> str:
415-
"""Request UID."""
414+
def request_id(self) -> str:
415+
"""Request ID."""
416416
return self.url.rpartition("/")[2]
417417

418+
@property
419+
def request_uid(self) -> str:
420+
warnings.warn(
421+
"`request_uid` has been deprecated, and in the future will raise an error."
422+
"Please use `request_id` from now on.",
423+
DeprecationWarning,
424+
stacklevel=2,
425+
)
426+
return self.request_id
427+
418428
@property
419429
def json(self) -> dict[str, Any]:
420430
"""Content of the response."""
@@ -533,7 +543,7 @@ def _warn(self) -> None:
533543
def update(self, request_id: str | None = None) -> None:
534544
self._warn()
535545
if request_id:
536-
assert request_id == self.request_uid
546+
assert request_id == self.request_id
537547
try:
538548
del self.reply
539549
except AttributeError:
@@ -558,7 +568,7 @@ def reply(self) -> dict[str, Any]:
558568
except Exception as exc:
559569
reply["error"].setdefault("message", str(exc))
560570

561-
reply.setdefault("request_id", self.request_uid)
571+
reply.setdefault("request_id", self.request_id)
562572
return reply
563573

564574
def log(self, *args: Any, **kwargs: Any) -> None:
@@ -599,10 +609,20 @@ class Jobs(ApiResponsePaginated):
599609
"""A class to interact with submitted jobs."""
600610

601611
@property
602-
def request_uids(self) -> list[str]:
603-
"""List of request UIDs."""
612+
def request_ids(self) -> list[str]:
613+
"""List of request IDs."""
604614
return [job["jobID"] for job in self._json_dict["jobs"]]
605615

616+
@property
617+
def request_uids(self) -> list[str]:
618+
warnings.warn(
619+
"`request_uids` has been deprecated, and in the future will raise an error."
620+
"Please use `request_ids` from now on.",
621+
DeprecationWarning,
622+
stacklevel=2,
623+
)
624+
return self.request_ids
625+
606626

607627
@attrs.define
608628
class Results(ApiResponse):

tests/integration_test_20_processing.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,24 @@ def test_processing_estimate_costs(api_anon_client: ApiClient) -> None:
6060

6161
def test_processing_get_jobs_status(api_anon_client: ApiClient) -> None:
6262
remote = api_anon_client.submit("test-adaptor-dummy", {"format": "foo"})
63-
request_uid = remote.request_uid
63+
request_id = remote.request_id
6464
with pytest.raises(HTTPError, match="400 Client Error: Bad Request"):
6565
remote.make_results()
66-
assert request_uid in api_anon_client.get_jobs(status="failed").request_uids
67-
assert request_uid not in api_anon_client.get_jobs(status="successful").request_uids
66+
assert request_id in api_anon_client.get_jobs(status="failed").request_ids
67+
assert request_id not in api_anon_client.get_jobs(status="successful").request_ids
6868

6969

7070
def test_processing_get_jobs_sortby(api_anon_client: ApiClient) -> None:
71-
uid1 = api_anon_client.submit("test-adaptor-dummy", {}).request_uid
72-
uid2 = api_anon_client.submit("test-adaptor-dummy", {}).request_uid
73-
uids = api_anon_client.get_jobs(sortby="-created").request_uids
74-
assert uids.index(uid2) < uids.index(uid1)
75-
assert [uid2] != api_anon_client.get_jobs(sortby="created", limit=1).request_uids
71+
id1 = api_anon_client.submit("test-adaptor-dummy", {}).request_id
72+
id2 = api_anon_client.submit("test-adaptor-dummy", {}).request_id
73+
ids = api_anon_client.get_jobs(sortby="-created").request_ids
74+
assert ids.index(id2) < ids.index(id1)
75+
assert [id2] != api_anon_client.get_jobs(sortby="created", limit=1).request_ids
76+
77+
78+
def test_deprecation_warnings(api_anon_client: ApiClient) -> None:
79+
with pytest.warns(DeprecationWarning):
80+
api_anon_client.submit("test-adaptor-dummy", {}).request_uid
81+
82+
with pytest.warns(DeprecationWarning):
83+
api_anon_client.get_jobs().request_uids

tests/integration_test_30_remote.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def test_remote_request(remote: Remote) -> None:
5353
}
5454

5555

56-
def test_remote_request_uid(remote: Remote) -> None:
57-
assert uuid.UUID(remote.request_uid)
56+
def test_remote_request_id(remote: Remote) -> None:
57+
assert uuid.UUID(remote.request_id)
5858

5959

6060
def test_remote_status(remote: Remote) -> None:
@@ -85,13 +85,13 @@ def test_remote_cleanup(
8585
url=api_root_url, key=api_anon_key, cleanup=cleanup, maximum_tries=0
8686
)
8787
remote = client.submit("test-adaptor-dummy", {})
88-
request_uid = remote.request_uid
88+
request_id = remote.request_id
8989
del remote
9090
time.sleep(1)
9191

9292
client = ApiClient(url=api_root_url, key=api_anon_key, maximum_tries=0)
9393
with raises:
94-
client.get_remote(request_uid)
94+
client.get_remote(request_id)
9595

9696

9797
def test_remote_datetimes(api_anon_client: ApiClient) -> None:

tests/integration_test_60_api_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_api_client_download_results(
1515
remote = api_anon_client.submit("test-adaptor-dummy", {})
1616
target = str(tmp_path / "test.grib")
1717

18-
result = api_anon_client.download_results(remote.request_uid, target)
18+
result = api_anon_client.download_results(remote.request_id, target)
1919
assert result == target
2020
assert os.path.exists(result)
2121

@@ -28,15 +28,15 @@ def test_api_client_get_process(api_anon_client: ApiClient) -> None:
2828

2929

3030
def test_api_client_get_remote(api_anon_client: ApiClient) -> None:
31-
request_uid = api_anon_client.submit("test-adaptor-dummy", {}).request_uid
32-
remote = api_anon_client.get_remote(request_uid)
33-
assert remote.request_uid == request_uid
31+
request_id = api_anon_client.submit("test-adaptor-dummy", {}).request_id
32+
remote = api_anon_client.get_remote(request_id)
33+
assert remote.request_id == request_id
3434
assert set(remote.headers) == {"User-Agent", "PRIVATE-TOKEN"}
3535

3636

3737
def test_api_client_get_results(api_anon_client: ApiClient) -> None:
38-
request_uid = api_anon_client.submit("test-adaptor-dummy", {}).request_uid
39-
results = api_anon_client.get_results(request_uid)
38+
request_id = api_anon_client.submit("test-adaptor-dummy", {}).request_id
39+
results = api_anon_client.get_results(request_id)
4040
assert isinstance(results, Results)
4141

4242

0 commit comments

Comments
 (0)