edumuellerFSL commented on code in PR #36781:
URL: https://github.com/apache/airflow/pull/36781#discussion_r1460827252


##########
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:
   You're right, it won't be possible to add another mapping with the same key. 
I think generalizing it in the map is a good start, and then both custom 
exceptions could reference the same record from the map and make it more 
specific.



-- 
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]

Reply via email to