Lee-W commented on code in PR #37570:
URL: https://github.com/apache/airflow/pull/37570#discussion_r1498585177


##########
tests/api_connexion/schemas/test_dataset_schema.py:
##########
@@ -162,6 +162,37 @@ def test_serialize(self, session):
         }
 
 
+class TestDatasetEventCreateSchema(TestDatasetSchemaBase):
+    def test_serialize(self, session):
+        d = DatasetModel("s3://abc")
+        session.add(d)
+        session.commit()
+        event = DatasetEvent(
+            id=1,
+            dataset_id=d.id,
+            extra={"foo": "bar"},
+            source_dag_id=None,
+            source_task_id=None,
+            source_run_id=None,
+            source_map_index=-1,
+        )
+        session.add(event)
+        session.flush()
+        serialized_data = dataset_event_schema.dump(event)
+        assert serialized_data == {
+            "id": 1,
+            "dataset_id": d.id,
+            "dataset_uri": "s3://abc",
+            "extra": {"foo": "bar"},
+            "source_dag_id": None,
+            "source_task_id": None,
+            "source_run_id": None,
+            "source_map_index": -1,

Review Comment:
   updated. thanks!



##########
airflow/api_connexion/endpoints/dataset_endpoint.py:
##########
@@ -301,3 +312,37 @@ def delete_dataset_queued_events(
         "Queue event not found",
         detail=f"Queue event with dataset uri: `{uri}` was not found",
     )
+
+
+@security.requires_access_dataset("POST")
+@provide_session
+@action_logging(
+    event=action_event_from_permission(
+        prefix=RESOURCE_EVENT_PREFIX,
+        permission=permissions.ACTION_CAN_CREATE,
+    ),
+)
+def post_dataset_event(session: Session = NEW_SESSION) -> APIResponse:
+    """Post dataset event."""
+    try:
+        json_body = dataset_event_schema.load(get_json_request_dict(), 
session=session)
+    except ValidationError as err:
+        raise BadRequest(detail=str(err))
+    uri = json_body["dataset_uri"]
+    dm = session.scalar(select(DatasetModel).where(DatasetModel.uri == 
uri).limit(1))
+    if not dm:
+        raise NotFound(title="Dataset not found", detail=f"Dataset with uri: 
'{uri}' not found")

Review Comment:
   updated



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to