Skip to content

Conversation

@Mirkazemi
Copy link
Contributor

Reference Issue

Public delete methods #1028

What does this PR implement/fix? Explain your changes.

The new functions allow the user to delete run, task, flow and database using API:
openml.runs.delete_run()
openml.tasks.delete_task()
openml.flows.delete_flow()
openml.datasets.delete_dataset()

How should this PR be tested?

The unit tests are added to the
tests/test_runs/test_run_functions.py
tests/test_tasks/test_task_functions.py
tests/test_flows/test_flow_functions.py
tests/test_datasets/test_dataset_functions.py

Copy link
Collaborator

@PGijsbers PGijsbers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfeurer Should we want additional error wrapping?

E.g. deleting a task with runs says:

>>> openml.tasks.delete_task(4263)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\repositories\openml-python\openml\tasks\functions.py", line 537, in delete_task
    return openml.utils._delete_entity("task", task_id)
  File "E:\repositories\openml-python\openml\utils.py", line 175, in _delete_entity
    result_xml = openml._api_calls._perform_api_call(url_suffix, "delete")
  File "E:\repositories\openml-python\openml\_api_calls.py", line 61, in _perform_api_call
    response = __read_url(url, request_method, data)
  File "E:\repositories\openml-python\openml\_api_calls.py", line 160, in __read_url
    return _send_request(
  File "E:\repositories\openml-python\openml\_api_calls.py", line 192, in _send_request
    __check_response(response=response, url=url, file_elements=files)
  File "E:\repositories\openml-python\openml\_api_calls.py", line 230, in __check_response
    raise __parse_server_exception(response, url, file_elements=file_elements)
openml.exceptions.OpenMLServerException: https://www.openml.org/api/v1/xml/task/4263 returned code 454: Task is executed in some runs. Delete these first - None

Deleting something not owned by you:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\repositories\openml-python\openml\runs\functions.py", line 1208, in delete_run
    return openml.utils._delete_entity("run", run_id)
  File "E:\repositories\openml-python\openml\utils.py", line 175, in _delete_entity
    result_xml = openml._api_calls._perform_api_call(url_suffix, "delete")
  File "E:\repositories\openml-python\openml\_api_calls.py", line 61, in _perform_api_call
    response = __read_url(url, request_method, data)
  File "E:\repositories\openml-python\openml\_api_calls.py", line 160, in __read_url
    return _send_request(
  File "E:\repositories\openml-python\openml\_api_calls.py", line 192, in _send_request
    __check_response(response=response, url=url, file_elements=files)
  File "E:\repositories\openml-python\openml\_api_calls.py", line 230, in __check_response
    raise __parse_server_exception(response, url, file_elements=file_elements)
openml.exceptions.OpenMLServerException: https://www.openml.org/api/v1/xml/run/10559886 returned code 393: Run is not owned by you - None

The messages are pretty clear though the stack trace perhaps a bigger than expected by an end-user. We could also use e.g. PermissionError for trying to delete others' entities.

@Mirkazemi Please include tests for common errors (deleting something that is not yours, deleting an entity with attached other entities (e.g. task with runs)). I suggest you wait with this until Matthias has chimed in on whether or not the exceptions should be wrapped.


run = openml.runs.run_model_on_task(model=clf, task=task, seed=rs)
run.publish()
TestBase._mark_entity_for_removal("run", run.run_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we want to mark the entities in other tests for removal as well - even though the tests should remove them. In case we introduce some error in the delete functions the entities will still be cleaned from the test server.

@mfeurer
Copy link
Collaborator

mfeurer commented Apr 21, 2021

I agree, we could add two new exceptions for the cases you mentioned above to make it easier for the user to understand what's going on and automatically parse the exceptions.

@PGijsbers
Copy link
Collaborator

Hi @Mirkazemi! I hope you are well :) If you're planning to continue working on this PR please let us know.

@PGijsbers PGijsbers self-assigned this Feb 23, 2023
@PGijsbers
Copy link
Collaborator

@mfeurer Can you have a quick look at the progress? In particular the testing against cached xml responses from the server. See for example the flow tests, which feature both an integration test that Mirkazemi had added, but below that also multiple new tests against cached responses.
The downside of the integrations tests are plenty:

  • they can be flaky as they depend on server stability
  • they are slower (by nature of having to communicate with the server)
  • and require either an extensive setup to keep independent from other tests (e.g., creating both a new task and a run to test for task can not be deleted because of associated runs), or would create dependencies (e.g., trying to delete already existing tasks/tasks generated by other tests, which is both hard to orchestrate and in case of server bugs might even result in unintended loss of data).

With the new server implementation, the server tests themselves will be responsible for ensuring the right behaviour for provided input. However, this will take a while to roll out (and for openml-python to use), so there is also a pro to actually doing integration tests (the openml-python tests are also used as server tests for now). My questions are thus:

  1. To what extend do you think we should keep/add integration tests (if any)?
  2. What do you think about the mocked xml response tests, and how they are currently structured?

Copy link
Collaborator

@mfeurer mfeurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things, but besides that, this PR looks good to me.

@PGijsbers
Copy link
Collaborator

Thanks! I'll process the feedback later and add similar tests for the other entities. I'll ping you when I'm done :)

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 97.61% and project coverage change: +0.07 🎉

Comparison is base (24cbc5e) 85.16% compared to head (54cfcda) 85.24%.

❗ Current head 54cfcda differs from pull request most recent head d725c1a. Consider uploading reports for the commit d725c1a to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1060      +/-   ##
===========================================
+ Coverage    85.16%   85.24%   +0.07%     
===========================================
  Files           38       38              
  Lines         4981     5008      +27     
===========================================
+ Hits          4242     4269      +27     
  Misses         739      739              
Impacted Files Coverage Δ
openml/datasets/__init__.py 100.00% <ø> (ø)
openml/runs/__init__.py 100.00% <ø> (ø)
openml/tasks/__init__.py 100.00% <ø> (ø)
openml/utils.py 91.25% <93.33%> (+0.03%) ⬆️
openml/_api_calls.py 86.44% <100.00%> (-0.08%) ⬇️
openml/datasets/functions.py 90.16% <100.00%> (+0.05%) ⬆️
openml/exceptions.py 96.66% <100.00%> (-0.11%) ⬇️
openml/flows/__init__.py 100.00% <100.00%> (ø)
openml/flows/functions.py 84.74% <100.00%> (+0.17%) ⬆️
openml/runs/functions.py 84.26% <100.00%> (+0.31%) ⬆️
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@PGijsbers PGijsbers merged commit 3c00d7b into openml:develop Mar 21, 2023
@PGijsbers
Copy link
Collaborator

Thanks @Mirkazemi for starting this PR 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants