Lee-W commented on code in PR #44130:
URL: https://github.com/apache/airflow/pull/44130#discussion_r1846457706
##########
airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -252,3 +252,32 @@ def get_dag_asset_queued_events(
],
total_entries=total_entries,
)
+
+
+@assets_router.delete(
+ "/dags/{dag_id}/assets/queuedEvent/{uri:path}",
+ status_code=status.HTTP_204_NO_CONTENT,
+ responses=create_openapi_http_exception_doc(
+ [
+ status.HTTP_400_BAD_REQUEST,
+ status.HTTP_404_NOT_FOUND,
+ ]
+ ),
+)
+def delete_dag_asset_queued_event(
+ dag_id: str,
+ uri: str,
+ session: Annotated[Session, Depends(get_session)],
+ before: OptionalDateTimeQuery = None,
+):
+ """Delete a queued asset event for a DAG."""
+ where_clause = _generate_queued_event_where_clause(dag_id=dag_id,
before=before, uri=uri)
+ delete_statement = (
+
delete(AssetDagRunQueue).where(*where_clause).execution_options(synchronize_session="fetch")
+ )
+ result = session.execute(delete_statement)
+ if result.rowcount == 0:
+ raise HTTPException(
+ status.HTTP_404_NOT_FOUND,
+ detail=f"Queue event with dag_id: `{dag_id}` and asset uri:
`{uri}` was not found",
Review Comment:
```suggestion
detail=f"Queued event with dag_id: `{dag_id}` and asset uri:
`{uri}` was not found",
```
##########
tests/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -523,6 +523,41 @@ def test_should_respond_404(self, test_client):
assert response.json()["detail"] == "Queue event with dag_id:
`not_exists` was not found"
+class TestDeleteDagAssetQueuedEvent(TestQueuedEventEndpoint):
+ def test_delete_should_respond_204(self, test_client, session,
create_dummy_dag):
+ dag, _ = create_dummy_dag()
+ dag_id = dag.dag_id
+ asset_uri = "s3://bucket/key/1"
+ self.create_assets(session=session, num=1)
+ asset_id = 1
+
+ self._create_asset_dag_run_queues(dag_id, asset_id, session)
+ adrq = session.query(AssetDagRunQueue).all()
+ assert len(adrq) == 1
+
+ response = test_client.delete(
+ f"/public/dags/{dag_id}/assets/queuedEvent/{asset_uri}",
+ )
+
+ assert response.status_code == 204
+ adrq = session.query(AssetDagRunQueue).all()
+ assert len(adrq) == 0
+
+ def test_should_respond_404(self, test_client):
+ dag_id = "not_exists"
+ asset_uri = "not_exists"
+
+ response = test_client.delete(
+ f"/public/dags/{dag_id}/assets/queuedEvent/{asset_uri}",
+ )
+
+ assert response.status_code == 404
+ assert (
+ response.json()["detail"]
+ == "Queue event with dag_id: `not_exists` and asset uri:
`not_exists` was not found"
Review Comment:
```suggestion
== "Queued event with dag_id: `not_exists` and asset uri:
`not_exists` was not found"
```
--
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]