Skip to content

Commit 621e1c3

Browse files
authored
Update migration guide and test docs (#316)
1 parent 8b48c59 commit 621e1c3

3 files changed

Lines changed: 58 additions & 27 deletions

File tree

docs/contributing/tests.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,16 @@ def _assert_error_response_equal(py_response, php_response) -> None:
133133
assert py_response.json()["code"] == php_response.json()["error"]["code"]
134134

135135
```
136+
137+
### Usage of the Database
138+
You frequently need to write tests which include fetching from or writing to the database.
139+
There is a test database that is prepopulated with data available for use as defined in our `compose.yaml` file.
140+
141+
The `expdb_test` and `user_test` connections automatically start a transaction during setup and perform a rollback during teardown.
142+
This means that as long as you do not `.commit()` any changes, the data will not persist.
143+
This is a good thing. We do not want our tests to have side effects, as it might lead to inconsistent behavior.
144+
145+
There is one situation where you may need to commit to the database: migration tests.
146+
Since the PHP API communicates to the database in a separate transaction, changes made within the transaction in "Python land" are not visible to PHP.
147+
In this case, be extremely careful! You *must* write the test so that even if things fail unexpectedly, there is no data left behind.
148+
Generally speaking, you want to use a context manager that cleans up after you. In some cases you may need to clean up after yourself during the test.

docs/migration.md

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,64 @@ largely functioning the same way. However, there are a few major deviations:
77
* Restriction or expansion of input types as appropriate.
88
* Standardizing authentication and access messages, and consistently execute those checks
99
before fetching data or providing error messages about the data.
10+
* Errors are returned in the [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457.html) standard, and HTTP status codes may be changed to be more semantically appropriate.
1011

1112
The list above is not exhaustive. Minor changes include, for example, bug fixes and the removal of unnecessary nesting.
1213
There may be undocumented changes, especially in edge cases which may not have occurred in the test environment.
1314
As the PHP API was underspecified, the re-implementation is based on a mix of reading old code and probing the API.
14-
If there is a behavioral change which was not documented but affects you, please [open a bug report](https://github.com/openml/server-api/issues/new?assignees=&labels=bug%2C+triage&projects=&template=bug-report.md&title=).
15+
If there is a behavioral change which was not documented but affects you, please [open a bug report](https://github.com/openml/server-api/issues/new?assignees=&labels=bug%2C+triage&projects=&template=bug-report.md&title=). Also feel free to open an issue on the issue tracker if you feel that we made a mistake with a decision on e.g., a new status code.
1516

1617
It is possible this migration guide is out of sync for endpoints not yet deployed to production (currently that includes them all).
1718
Before an endpoint is deployed to production we will ensure that the documentation is up-to-date to the best of our knowledge.
1819

19-
## All Endpoints
20-
The following changes affect all endpoints.
20+
# RFC 9457 Errors
21+
Errors will follow the RFC9457 standard. However, the original "code" is preserved through a custom field.
22+
Take for example the "Dataset not found" response for trying to access a dataset that does not exist.
2123

22-
### Error on Invalid Input
23-
When providing input of invalid types (e.g., a non-integer dataset id) the HTTP header
24-
and JSON content will be different.
24+
```diff title="CURL Commands"
25+
curl -i https://www.openml.org/api/v1/json/data/1000000
26+
- HTTP/1.1 412 Precondition Failed
27+
- ...
28+
- {"error":{"code":"111","message":"Unknown dataset"}}
29+
30+
+ HTTP/1.1 404 Not Found
31+
+ ...
32+
+ {"type":"https://openml.org/problems/dataset-not-found","title":"Dataset Not Found","status":404,"detail":"No dataset with id 100000 found.","code":"111"}
33+
```
34+
35+
You will notice that the response still contains a "code" of "111" (though as a top level property not embedded in the "error" scope).
36+
This field is included to support the migration of clients, but should be considered deprecated.
37+
As per the RFC9457 standard, the "type" field now includes the unique code for the error.
38+
The "title" field is a human readable summary of the general issue and the "detail" field may provide additional information for the specific request.
39+
They _will_ be resolvable URIs in the future, providing a page with more information.
40+
41+
In some cases the JSON endpoints previously returned XML ([example](https://github.com/openml/OpenML/issues/1200)), the new API always returns JSON.
42+
43+
# Appropriate HTTP Status Codes
44+
There are several cases where the PHP server did not provide semantically correct status codes.
45+
The Python server aims to correct that.
46+
The errors that changed which are most likely to occur are probably errors when there is no result, or when the input is incorrect.
47+
48+
49+
For not being able to resolve an identifier ("dataset not found"):
2550

2651
```diff title="HTTP Header"
2752
- 412 Precondition Failed
28-
+ 422 Unprocessable Entity
53+
+ 404 Not Found
54+
```
55+
56+
When authentication is required but not provided or not valid:
57+
58+
```diff title="HTTP Header"
59+
- 412 Precondition Failed
60+
+ 401 Unauthorized
2961
```
3062

31-
```diff title="JSON Content"
32-
- {"error":{"code":"100","message":"Function not valid"}}
33-
+ {"detail":[{"loc":["query","_dataset_id"],"msg":"value is not a valid integer","type":"type_error.integer"}]}
63+
For incorrect input (e.g., providing a string instead of an integer identifier):
64+
65+
```diff title="HTTP Header"
66+
- 412 Precondition Failed
67+
+ 422 Unprocessable Entity
3468
```
3569

3670
!!! warning "Input validation has been added to many end points"
@@ -39,23 +73,7 @@ and JSON content will be different.
3973
These endpoints now do enforce stricter input constraints.
4074
Constraints for each endpoint parameter are documented in the API docs.
4175

42-
### Other Errors
43-
For any other error messages, the response is identical except that outer field will be `"detail"` instead of `"error"`:
44-
45-
```diff title="JSON Content"
46-
- {"error":{"code":"112","message":"No access granted"}}
47-
+ {"detail":{"code":"112","message":"No access granted"}}
48-
```
49-
50-
In some cases the JSON endpoints previously returned XML ([example](https://github.com/openml/OpenML/issues/1200)), the new API always returns JSON.
51-
52-
```diff title="XML replaced by JSON"
53-
- <oml:error xmlns:oml="http://openml.org/openml">
54-
- <oml:code>103</oml:code>
55-
- <oml:message>Authentication failed</oml:message>
56-
- </oml:error>
57-
+ {"detail": {"code":"103", "message": "Authentication failed" } }
58-
```
76+
# Endpoint Specific Notes
5977

6078
## Datasets
6179

File renamed without changes.

0 commit comments

Comments
 (0)