edumuellerFSL commented on code in PR #36781:
URL: https://github.com/apache/airflow/pull/36781#discussion_r1460338218
##########
airflow/api_connexion/endpoints/dataset_endpoint.py:
##########
@@ -32,14 +34,42 @@
dataset_schema,
)
from airflow.models.dataset import DatasetEvent, DatasetModel
+from airflow.security import permissions
from airflow.utils.db import get_query_count
+from airflow.utils.log.action_logger import action_event_from_permission
from airflow.utils.session import NEW_SESSION, provide_session
+from airflow.www.decorators import action_logging
if TYPE_CHECKING:
from sqlalchemy.orm import Session
from airflow.api_connexion.types import APIResponse
+RESOURCE_EVENT_PREFIX = "dataset"
+
+
[email protected]_access_dataset("DELETE")
+@provide_session
+@action_logging(
+ event=action_event_from_permission(
+ prefix=RESOURCE_EVENT_PREFIX,
+ permission=permissions.ACTION_CAN_DELETE,
+ ),
+)
+def delete_dataset(*, uri: str, session: Session = NEW_SESSION) -> APIResponse:
+ """Delete a Dataset."""
+ dataset = session.scalar(select(DatasetModel).where(DatasetModel.uri ==
uri))
+ if dataset is None:
+ raise NotFound(
+ "Dataset not found",
+ detail=f"The Dataset with uri: `{uri}` was not found",
+ )
+ if dataset.consuming_dags or dataset.producing_tasks:
+ raise AlreadyExists(detail="Dataset is still referenced by other DAG")
Review Comment:
imo using status code 409 is the correct approach here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]