Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/demo_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Task,
Visibility,
create_submission_with_upload,
delete_submission,
)

submission = DatasetSubmission(
Expand Down Expand Up @@ -53,3 +54,6 @@
)

print(response)

# Completely remove the submission
delete_submission(response["submission"]["id"], enable_logging=True)
2 changes: 1 addition & 1 deletion docs/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ A submission that has not been published can be deleted, together with every fil
```python
from datacollective import delete_submission

delete_submission(submission_id="your-submission-id")
delete_submission(submission_id="your-submission-id", enable_logging=True)
```

Deleting a published submission, or one that belongs to another organization, raises `PermissionError`.
Expand Down
15 changes: 12 additions & 3 deletions src/datacollective/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,14 @@ def create_submission_with_upload(
return response


def delete_submission(submission_id: str) -> None:
def delete_submission(submission_id: str, enable_logging: bool = False) -> None:
"""
Delete a dataset submission that has not been published, and every file
uploaded for it. WARNING: The deletion cannot be undone!

Args:
submission_id: Dataset submission ID.
enable_logging: Whether to enable SDK logging to console and a local log file.

Raises:
ValueError: If submission_id is empty.
Expand All @@ -216,6 +217,14 @@ def delete_submission(submission_id: str) -> None:
if not submission_id or not submission_id.strip():
raise ValueError("`submission_id` must be a non-empty string")

_enable_logging(enable_logging)

url = f"{_get_api_url()}/submissions/{submission_id}"
# 204 No Content: there is no body to return.
_send_api_request("DELETE", url)
logger.info(f"Deleting submission {submission_id}...")
try:
# 204 No Content: there is no body to return.
_send_api_request("DELETE", url)
except Exception as exc:
logger.error(f"Failed to delete submission {submission_id}: {exc}")
raise
logger.info(f"Submission {submission_id} deleted.")
Loading